Programming Tutorials

Comment on Tutorial - FileInputStream - sample program in Java By Sam Chen



Comment Added by : anne

Comment Added at : 2011-11-22 10:50:10

Comment on Tutorial : FileInputStream - sample program in Java By Sam Chen
You can save a file from the content of the input. This is my method to do it.

public static void SaveText() throws FileNotFoundException {
try {
System.out.println("Enter the string");
Scanner ip = new Scanner(System.in);
String str = ip.nextLine();
ip.close();

byte[] source = str.getBytes();
FileOutputStream fos = new FileOutputStream("D:/test.txt");
fos.write(source);
System.out.println("Finished");
} catch (IOException ex) {
Logger.getLogger(Q2.class.getName()).log(Level.SEVERE, null, ex);
}
}


View Tutorial