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



Subscribe to Tutorials

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. I need to creat class. Write in class void named r
View Tutorial          By: Aliarth at 2012-11-18 00:03:15

2. its a very very good artical
View Tutorial          By: xyz at 2011-06-17 08:12:26

3. hi ramlak,i am getting sender *** time out at step
View Tutorial          By: agnas at 2008-05-02 01:29:33

4. Hi,
Please tell me how to execute the above

View Tutorial          By: DurgaPrasad at 2011-11-24 06:04:48

5. I'm trying to learn navigating between activities.
View Tutorial          By: Ben at 2012-01-17 23:42:38

6. i am getting a force close...can anyone please hel
View Tutorial          By: jack at 2012-03-22 15:18:37

7. Hi
I can compile it
root$ javac -cp

View Tutorial          By: Tebogo Modiselle at 2014-10-31 08:47:09

8. How to use it
View Tutorial          By: Ted at 2011-12-23 07:23:20

9. Hi,
i executed this program successfully in

View Tutorial          By: Praveen at 2010-07-14 01:05:37

10. Wow NIce
View Tutorial          By: Zahid ALi at 2015-01-16 22:35:45