java.util.scanner

Difference between buffered reader and file reader and scanner class [duplicate]

冷暖自知 提交于 2019-12-03 06:05:08
问题 This question already has answers here : Scanner vs. BufferedReader (12 answers) Closed 5 years ago . Can anyone explain me the difference between the class BufferedReader , FileReader and Scanner ? and which one to use when I want to read a text file? 回答1: Well: FileReader is just a Reader which reads a file, using the platform-default encoding (urgh) BufferedReader is a wrapper around another Reader , adding buffering and the ability to read a line at a time Scanner reads from a variety of

Java Scanner - why do I get this error? [closed]

烂漫一生 提交于 2019-12-02 22:37:13
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I'm not new to java, but I cannot figure out why I get this Scanner error. The code compiles fine, but I get the following runtime error Enter item number: Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:840) at java.util.Scanner.next(Scanner.java:1461) at

Java Scanner with InputStream not working

心已入冬 提交于 2019-12-02 22:18:57
问题 I am reading an InputStream (fis) from a source and on which I have to do some multiple search. I am using Scanner class and I instantiate it after every search. But it works only first time. Is there a way to reset the Scanner object? I have no control over the stream. Scanner sc = new Scanner(new BufferedReader(new InputStreamReader( fis, MIFConstants.ENCODING_UTF_8))); int count = 0; while (sc.hasNextLine()) { count++; sc.nextLine(); } System.out.println(count); sc = new Scanner(new

Difference between buffered reader and file reader and scanner class [duplicate]

馋奶兔 提交于 2019-12-02 20:46:20
This question already has an answer here: Scanner vs. BufferedReader 12 answers Can anyone explain me the difference between the class BufferedReader , FileReader and Scanner ? and which one to use when I want to read a text file? Well: FileReader is just a Reader which reads a file, using the platform-default encoding (urgh) BufferedReader is a wrapper around another Reader , adding buffering and the ability to read a line at a time Scanner reads from a variety of different sources, but is typically used for interactive input. Personally I find the API of Scanner to be pretty painful and

Java JDBC Limited Scanner

和自甴很熟 提交于 2019-12-02 20:46:12
问题 Im a beginner looking to create a scanner that inserts user input data into a MySQL database I've created for a fitness application. My current database is laid out with the following headings: Date_Created , Program_Name , Excercise_Name , Total_Sets , Set_1_Weight , Set_1_Reps , Set_2_Weight , etc. up to Set 10. I'm looking for assistance to allow the scanner to query amount of sets input by the user in Total_Sets . Any help would be greatly appreciated. Thanks. 来源: https://stackoverflow

Java - parsing text using delimiter for separating different arguments

末鹿安然 提交于 2019-12-02 20:15:44
问题 How would you use multiple delimiters or a single delimiter to detect and separate out different string matches? For example, I use a Scanner to parse in the following string: MrsMarple=new Person(); MrsMarple.age=30; I would like to separate out this string to determine, in sequence, when a new person is being created and when their age is being set. I also need to know what the age is being set to. There can be anything between and/or either side of these arguments (there doesn't

Why is nextDouble() from the Scanner method sending me “Exception”

我的梦境 提交于 2019-12-02 20:06:38
问题 I'm suppose to enter 2 numbers, one int that is the amount to withdraw and one double which is the balance (with a space between them). Since every withdraw charges a fee of 0.5, balance must be a double. And thats what must be printed. I get error at nextDouble, why? I have just 1 month coding, I thought this was going to be a piece of cake, I think BASIC syntax ruined me 30 years ago :( import java.util.Scanner; public class Test { public static void main(String[] args) { //init variables

Begin the reading of a file from a specific line

你。 提交于 2019-12-02 19:36:20
问题 i have a file similaire to this : ... The hotspot server JVM has specific code-path optimizations # which yield an approximate 10% gain over the client version. export CATALINA_OPTS="$CATALINA_OPTS -server" #############HDK1001############# # Disable remote (distributed) garbage collection by Java clients # and remove ability for applications to call explicit GC collection export CATALINA_OPTS="$CATALINA_OPTS -XX:+DisableExplicitGC" # Check for application specific parameters at startup if [

Unreported exception java.io.FileNotFoundException;?

北城余情 提交于 2019-12-02 17:35:44
问题 I want to open a file and scan it to print its tokens but I get the error: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown Scanner stdin = new Scanner (file1); The file is in the same folder with the proper name. import java.util.Scanner; import java.io.File; public class myzips { public static void main(String[] args) { File file1 = new File ("zips.txt"); Scanner stdin = new Scanner (file1); String str = stdin.next(); System.out.println(str); } }

using scanner to read file but skip blank lines into a 2d array

假如想象 提交于 2019-12-02 17:19:52
问题 I am struggling to use scanner class to read in a text file while skipping the blank lines. Any suggestions? Scanner sc = new Scanner(new BufferedReader(new FileReader("training2.txt"))); trainingData = new double[48][2]; while(sc.hasNextLine()) { for (int i=0; i<trainingData.length; i++) { String[] line = sc.nextLine().trim().split(" "); if(line.length==0) { sc.nextLine(); }else{ for (int j=0; j<line.length; j++) { trainingData[i][j] = Double.parseDouble(line[j]); } } } } if(sc.hasNextLine()