In java, how to get an input from a text file?
http://docs.oracle.com/javase/tutorial/essential/io/rafs.html http://www.cs.wcupa.edu/~rkline/java/file_access.html http://www.javacoffeebreak.com/faq/faq0004.html
First import java.io.*; and java.util.*; than there are so many build-in class that can do the jobs .But if you are to use Scanner class than you can easily do the work..for that In the main class Scanner in = new Scanner(new FileReader("text.in")); //take the file that should be located in the same directory otherwise put location of path like ("c://home/Documents") ....// BufferedWriter inp = new BufferedWriter(new FileWriter("textout.txt")); In scanner class there are so many methods in.next()//read by character in.hasNext(); in.nextLine();read line by line... please refer this link ..
Thanks :))
Join our real-time social learning platform and learn together with your friends!