Skip to content

Instantly share code, notes, and snippets.

@mbround18
Created April 7, 2019 04:58
Show Gist options
  • Save mbround18/a9165f3ed343d155b5498561787c0523 to your computer and use it in GitHub Desktop.
Save mbround18/a9165f3ed343d155b5498561787c0523 to your computer and use it in GitHub Desktop.
package filepackage;
import java.io.*;
public class FileWritingStreamWay {
public static void main(String[] args) {
InputStream istream;
OutputStream ostream=null;
int c;
final int EOF = -1;
istream = System.in;
File outFile = new File("Data.txt");
System.out.println("Type characters to write in File – Press Ctrl+z to end ");
try {
ostream = new FileOutputStream(outFile);
while ((c = istream.read()) != EOF)
ostream.write(c);
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
} finally {
try {
istream.close();
ostream.close();
} catch (IOException e) {
System.out.println("File did not close");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment