//Instantiate a stream, reader and tokenizer FileInputStream streamVariableName = newFileInputStream(fileNameOrPath); InputStreamReader readerVariableName = new InputStreamReader(streamVariableName); StreamTokenizer tokenVariableName = new StreamTokenizer(readerVariableName); //Read from the tokenizer until it is empty while(tokenVariableName.nextToken() != tokenVariableName.TT_EOF) { ... } //Close the file streamVariableName.close();
//Instantiate a stream, and a PrintWriter FileOutputStream streamVariableName = newFileOutputStream(fileNameOrPath); PrintWriter printerVariableName = new PrintWriter(streamVariableName) //Write a string to the file printerVariableName.print(string); //Write a string and a newline to the file printerVariableName.println(string); //Close the file streamVariableName.close();