Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / January 2006

Tip: Looking for answers? Try searching our database.

Creating a file in a directory

Thread view: 
kevinhu19@gmail.com - 30 Dec 2005 21:13 GMT
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" );
OutputStream savedFile = new FileOutputStream( newFile );

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

-Kevin
Mark Thomas - 31 Dec 2005 18:52 GMT
> I'm able to create a new file using
>
[quoted text clipped - 8 lines]
>
> 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
Roedy Green - 03 Jan 2006 00:48 GMT
On 30 Dec 2005 13:13:01 -0800, "kevinhu19@gmail.com"
<kevinhu19@gmail.com> wrote, quoted or indirectly quoted someone who
said :

>where newFile is a File object.  However, how do I create this new file
>in a directory other than the current working directory?

use an absolute file reference, or a relative on with ../ in it to
navigate to some other directory.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.