



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















keyboard
monitor terminal console
standard input stream
standard output stream file input stream LOAD READ file output stream SAVE WRITE
docsity.com
Reading and Writing Text Files
Scanner
import java.io.;*
int number = scanner.nextInt();
String input = scanner.nextLine(); int number = Integer.parseInt(input);
FileReader rdr = newFileReader("input.txt");
Scanner fin = new Scanner(rdr);
FileNotFoundException
File file = new File ("input.txt");
Scanner fin;
if(file.exists()){
fin = new Scanner(file);
} else {
//ask for another file
}
java.io.File
associated with an actual file on hard drive used to check file's status
File(
exists() canRead() , canWrite() isFile() , isDirectory()
PrintWriter fout = new PrintWriter("output.txt"); fout.println(29.95); fout.println(new Rectangle(5, 10, 15, 25));
fout.println("Hello, World!");
fout.close();
in = new FileReader(“c:\homework\input.dat”);
java.io.IOException