• Text Files for Java


    • java.io.File
    • java.io.FileWriter
    • java.io.IOException
    • java.io.PrintWriter
    • java.util.Scanner

       Declaring the Reader and Writer:

           Scanner in = new Scanner(new File("(In File Location"));
           PrintWriter out = new PrintWriter(new FileWriter("(Out File Location)"));

       Reading from text file:

           String Li = in.nextLine(); (This will read in the next line in the text file to the String Li)

       Writing to text file:


       Be sure to always close the text files!