cancel
Showing results for 
Search instead for 
Did you mean: 

File Handling

Former Member
0 Kudos

I am a begineer in Java and trying to write some data into a file. I have the below program and it works fine, I want to create the output in C:\myfile.txt, but I dont know how to give the c:\ Path, would some one kindly help me. Thanks.

import java.io.*;

public class FileApp

{

// Main method

public static void main (String args[])

{

// Stream to write file

FileOutputStream fout;

try

{

// Open an output stream

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

// Print a line of text

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

// Close our output stream

fout.close();

}

// Catches any error conditions

catch (IOException e)

{

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

System.exit(-1);

}

}

}

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

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