Re: Creating a file in a directory



kevinhu19@xxxxxxxxx wrote:
I'm able to create a new file using

OutputStream savedFile = new FileOutputStream( newFile );

where newFile is a File object.  However, how do I create this new file
in a directory other than the current working directory?  For example
assume there is a directory in the current working directory 'test' and
I want to create a file in 'test/blah.txt'

I tried something like this:

File newFile = new File( "test/blah.txt" );

add: newFile.createNewFile(); in here.

OutputStream savedFile = new FileOutputStream( newFile );

But Linux (FC2) keeps saying that "test/blah.txt" is a directory, not a
file.  Any clue?

-Kevin


Mark .



Relevant Pages

  • Re: Creating a file in a directory
    ... >where newFile is a File object. ... >in a directory other than the current working directory? ... use an absolute file reference, or a relative on with ../ in it to ...
    (comp.lang.java.help)
  • Creating a file in a directory
    ... OutputStream savedFile = new FileOutputStream(newFile); ... in a directory other than the current working directory? ...
    (comp.lang.java.help)
  • Re: File Can Not be Found
    ... RigasMinho wrote: ... No clue why it gives me this error because the file is named correctly ... and is in the same working directory as the jsp file. ...
    (comp.lang.java.programmer)