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



Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. ahmm I guess This is a VB6 program? or how can I g
View Tutorial          By: kelvin at 2011-02-27 14:07:44

2. I an going to try this code.
View Tutorial          By: Bhagawati Prasad at 2010-02-06 02:45:10

3. it is super
View Tutorial          By: vinod at 2011-09-03 04:06:02

4. i had a problem in running a java software jdk1.5.
View Tutorial          By: tej at 2009-06-30 08:50:27

5. can u please send me the code for sending sms from
View Tutorial          By: Vicky at 2008-03-20 02:34:27

6. Hi, I have mobile application developed in java w
View Tutorial          By: Meenu at 2008-12-30 02:46:54

7. Hi, still having problem with 'Permission denied'.
View Tutorial          By: Dorjoo at 2012-05-18 19:00:22

8. Nice Explanation.....
View Tutorial          By: Vinoth at 2012-06-20 09:37:21

9. I'm sorry but your closing statement...

View Tutorial          By: Al Scherer at 2009-09-15 09:33:24

10. Nice article...
View Tutorial          By: Sudhanshu at 2012-08-02 06:19:42