Checking hasNextLine() for a file scanner Programming Software Development by dmanw100 … = new File(fileName); Scanner dataFile = new Scanner(playerFile); while(dataFile.hasNextLine()) [/CODE] Why would datafile… Re: Checking hasNextLine() for a file scanner Programming Software Development by dmanw100 … Scanner dataFile = new Scanner(playerFile); //new Scanner dataFile while(dataFile.hasNextLine()) //while there is a next line { Player temp = new Player… Re: Checking hasNextLine() for a file scanner Programming Software Development by Rafael_9 In my experience, hasNextLine( ) goes crazy when the Scanner is created with `new Scanner (new File(...))` and there are non-ascii characters in the file (such as á, ñ, ..). As suggested, by creating the Scanner `new Scanner (new FileInputStream(...))` the problem disappears. Re: Checking hasNextLine() for a file scanner Programming Software Development by dickersonka its not open from another application is it? also wrap a try catch around and check and make sure it is accessing it properly Re: Checking hasNextLine() for a file scanner Programming Software Development by dickersonka and is an exception caught or no? Re: Checking hasNextLine() for a file scanner Programming Software Development by dmanw100 No exception is caught when this loop executes. I'm really stumped! :( Re: Checking hasNextLine() for a file scanner Programming Software Development by dickersonka just by chance, try moving the bracket after the while loop first comment, to be on the same line as the while statement also did you initialize your array thePlayers? trying taking everything out, and in the while loop just do a println on dataFile.nextLine() think there might be something with player in there possibly affecting it Re: Checking hasNextLine() for a file scanner Programming Software Development by dmanw100 No those changes didn't affect it's ability to read from the file. I'm going to try changing some other pieces of code though. Re: Checking hasNextLine() for a file scanner Programming Software Development by dmanw100 Ok it definitely is not finding the first line in the file. I simply removed the test for the first line and it chocked up and died a spectacular java ioexception death. The Players.txt file is in the same directory so I'm not sure why it can't find the first line. Re: Checking hasNextLine() for a file scanner Programming Software Development by dickersonka for some reason the file doesn't start with a eof character does it? try recreating the file and make sure its closed Re: Checking hasNextLine() for a file scanner Programming Software Development by BestJewSinceJC I'd be willing to bet that if you changed your code to this, then your code would work. I've never actually seen somebody use "File" as an argument to a Scanner, so excuse me if I'm wrong, but I don't think it should be used. File is a class that represents a File, is it not? A File and a FileInputStream are not the same thing, I don't … Re: Checking hasNextLine() for a file scanner Programming Software Development by ~s.o.s~ > for some reason the file doesn't start with a eof character does it? EOF isn't a character, this is one of the reasons why the [ICODE]read [/ICODE]method in Java and the [ICODE]getchar[/ICODE]/[ICODE]fgetc [/ICODE]function in C returns an [ICODE]int [/ICODE]instead of a [ICODE]char[/ICODE] [hint: since char is unsigned, there would be no … Re: Checking hasNextLine() for a file scanner Programming Software Development by JamesCherrill Interesting... A quick look at the source code for Scanner shows that the File constructor immdiately creates a FileInputStream from the file and proceeds with that, so just passing the stream rather than the file shouldn't make any difference. Problems with non-ascii chars are much more likely to be a problem with the default charset not … Help with my GroupProgram Programming Software Development by cloud02 … called intns */ public void readFile(){ int index = 0; while (reader.hasNextLine()){ String[] temp = reader.nextLine().split(", "); // Store the… void checkInside(int number) throws Exception { String count; if ( scan.hasNextLine() == false ) { count = Integer.toString(number); FileWriter out = new … Re: Help with my GroupProgram Programming Software Development by cloud02 …called intns */ public void readFile(){ int index = 0; while (reader.hasNextLine()){ String[] temp = reader.nextLine().split(", "); // Store … void checkInside(int number) throws Exception { String count; if ( scan.hasNextLine() == false ) { count = Integer.toString(number); FileWriter out = new… Need help with the java code! Programming Software Development by zantex … { input = console.nextDouble(); // clear trailing newline from buffer if (console.hasNextLine()) console.nextLine(); return input; } catch (InputMismatchException e) { System.out.println… reading from a txt file Programming Software Development by polska03 …FileIO fio=new FileIO(s); while(fio.hasNextLine()) { if(fio.hasNextInt()==false){ throw new… not opened"); }else{ return scan.hasNextLine(); } }//hasNextLine public String getNextLine() throws Exception{ if(scan… Stack Implementation Programming Software Development by anirban007 …new FileReader("prefix.txt")); while(in.hasNextLine()) { prefix(in.nextLine()); } in.close();…"); in = new Scanner(fob); while(in.hasNextLine()) { String line = in.nextLine(); palindrome(line);…------Balanced Parenthesis check using Stack-----"); while(in.hasNextLine()) { String line = in.nextLine(); parenthesis(line… Need Help With a Java Program That Will Indent Code From Another Java File Programming Software Development by Brian_18 … Scanner jfile = new Scanner(new File(fileN)); while (jfile.hasNextLine()) { String text = jfile.nextLine(); if (text.contains("…new PrintStream(new File("words2.txt")); while (input.hasNextLine()) { String text = input.nextLine(); echoFixed(text, output);… FileInput/Output Stream on JTextField Programming Software Development by cathgodarve …quot;\n"; storeAll1=storeAll1+temp1; } while(fr2.hasNextLine()) { String temp2=fr2.nextLine()+"\n"; …storeAll2=storeAll2+temp2; } while(fr3.hasNextLine()) { String temp3=fr3.nextLine()+"\n"; storeAll3… Java - Arrays Programming Software Development by saurabh2007 …]; int[] stdt; int[] answer = answerKey(); while (inScan2.hasNextLine()) { String id1 = inScan2.next(); ECHSid[temp] = id1…= inScan2.nextLine(); } String aa = inScan.nextLine(); while (inScan.hasNextLine()) { String id = inScan.next(); CitizenshipID[count] = id;… Parsing a file for Sets and Maps Programming Software Development by kweigand …Scanner in = new Scanner(new File(filename)); while (in.hasNextLine()) { String agentNum = in.nextLine(); String sub = agentNum.… out = new PrintWriter("readfile.txt"); while (sc2.hasNextLine()) { Scanner s2 = new Scanner(sc2.next()); @SuppressWarnings("… Need a Method That Will Split a Java File Into Lines By {, }, ;, and // Programming by Brian_18 …new PrintStream(new File("words2.txt")); while (input.hasNextLine()) { String text = input.nextLine(); echoFixed(text, output);…new PrintStream(new File("words2.txt")); while (input.hasNextLine()) { String text = input.nextLine(); echoFixed(text, output); … TicTacToe equivalent with a twist using socket programming in Java Programming Software Development by M_27 …private void processCommands() { while (input.hasNextLine()) { var command = input.nextLine(); … private void processCommands() { while (input.hasNextLine()) { var command = input.nextLine(); … Hey check out my prog. It has an error can u find it? Programming Software Development by buggytoast … Scanner in = new Scanner(inFile); while (in.hasNextLine()) { Scanner lineScanner = new Scanner(in.nextLine());… Scanner in = new Scanner(inFile); while (in.hasNextLine()) { Scanner lineScanner = new Scanner(in.nextLine()); lineScanner… Source Code that don't work? Programming Software Development by buggytoast … Scanner in = new Scanner(inFile); while (in.hasNextLine()) { Scanner lineScanner = new Scanner(in.nextLine());… Scanner in = new Scanner(inFile); while (in.hasNextLine()) { Scanner lineScanner = new Scanner(in.nextLine()); lineScanner… Stuck: Exception Handling and reading text from file Programming Software Development by LevelSix … number of words */ public int getWordCount() { while (in.hasNextLine()) { for(int i = 1; i <= in.nextLine…the number of lines */ public int getLineCount() { while (in.hasNextLine()) { lines++; } return lines; } /** Gets the number of… Re: Stuck: Exception Handling and reading text from file Programming Software Development by LevelSix …boolean done = false; while (!done) { if (in.hasNextLine() == true) { for(int i = 1; i …() { done = false; while (!done) { if(in.hasNextLine()) lines++; else lines = 0; } return lines; }… Re: Stuck: Exception Handling and reading text from file Programming Software Development by LevelSix …(reader); boolean done = false; while (!done) { if (in.hasNextLine() == true) { lines++; while(in.hasNextLine()) { int j = 0; int i = 1; file = in… Re: Stuck: Exception Handling and reading text from file Programming Software Development by LevelSix …done = false; while (!done) { while(in.hasNextLine()) { lines++; int j = 0; int i…num = array.length; chars += num; if(in.hasNextLine() == false) done = true; } } }…