Created
April 7, 2019 04:58
-
-
Save mbround18/a9165f3ed343d155b5498561787c0523 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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