How to use hadoop for text file?

How to use while loop for text file?

  • I am having problem with the while loop for the text file. Can anyone help me please? Much help is appreciated. Thanks. Part A Instead of writing a separate line to read each word (or number / item) in your text file use a while loop and have the ending condition be the false for the next statement. Part B Generate 10 random numbers between 100 and 200 and write them to a text file. I get stuck at the while loop part for Part A. import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Project7 { public static void main(String[] args) throws FileNotFoundException { File file = new File ("word.txt"); Scanner myScan = new Scanner (file); String fil = myScan.next(); System.out.println(fil); System.out.println(myScan.next()); System.out.println(myScan.next()); System.out.println(myScan.hasNext()); } }

  • Answer:

    I think you need something like String fil; while ( (file = myScan.next())!= null){ System.out.println(fil); } or while(myScan.hasNext()){ System.out.println( myScan.next()); } hope it helps!

Sayee at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.