Computer Science
Page Navigation
- Seaford High School
- Java Text Files
-
Text Files for Java
Imports:
- 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:
out.println(String);Be sure to always close the text files!
in.close();
out.close();