Write a File

Hi,

I am new to Java Programming . I can't compile my program. I have installed latest JDK version. I want to make "myfile.txt" file, which will have "hello world!" written in it. Do I need to install something else?

import java.io.*;

publicclass MyFirstFileWritingApp{

publicstaticvoid main (String args[])

{

FileOutputStream fout;

try

{

fout =new FileOutputStream ("myfile.txt");

new PrintStream(fout).println ("hello world!");

fout.close();

}

catch (IOException e)

{

System.err.println ("Unable to write to file");

System.exit(-1);

}

}

}

[1280 byte] By [JavaMaxa] at [2007-11-26 15:32:11]
# 1

try this:

try {

BufferedWriter out = new BufferedWriter(new FileWriter("outfilename"));

out.write("aString");

out.close();

} catch (IOException e) {

}

check out

http://java.sun.com/docs/books/tutorial/essential/io/

manuel.leiriaa at 2007-7-8 21:49:06 > top of Java-index,Java Essentials,Java Programming...
# 2
It's working now. :-)Thanks.
JavaMaxa at 2007-7-8 21:49:06 > top of Java-index,Java Essentials,Java Programming...