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 / General / April 2008

Tip: Looking for answers? Try searching our database.

FileOutputStream Does Not Create File?

Thread view: 
Jason Cavett - 25 Apr 2008 15:24 GMT
I'm trying to extract a ZIP file to a temporary directory
(System.getProperty("java.io.tmpdir")) and I keep getting the
following exception when I get to this line:

FileOutputStream fos = new FileOutputStream(TEMP_DIR +
entry.getName());

The exception is:

java.io.FileNotFoundException: C:\data\myusername\Desktop\zipped.txt
(The system cannot find the path specified)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:70)
    at hasrd.gui.skin.ThemeLoader.loadTheme(ThemeLoader.java:82)
    at hasrd.gui.skin.ThemeLoader.loadTheme(ThemeLoader.java:57)
    at hasrd.TestZipInput.main(TestZipInput.java:11)

Can a FileOutputStream create a directory if it does not already
exist?  Is there something else I'm doing wrong?

Thanks
Thomas Kellerer - 25 Apr 2008 16:04 GMT
Jason Cavett wrote on 25.04.2008 16:24:
> Can a FileOutputStream create a directory if it does not already
> exist?  
No. You need to use a File object to first create the directory, e.g. File.mkdirs()

Thomas
Leonard Milcin - 25 Apr 2008 16:09 GMT
> I'm trying to extract a ZIP file to a temporary directory
> (System.getProperty("java.io.tmpdir")) and I keep getting the
[quoted text clipped - 16 lines]
> Can a FileOutputStream create a directory if it does not already
> exist?

No, it won't create it. It's your responsibility.

> Is there something else I'm doing wrong?

Yes. You should create File object and pass it as a parameter to the
constructor of FileOutputStream. You can use mkdirs
http://java.sun.com/javase/6/docs/api/java/io/File.html#mkdirs() to
create the directory.

And third thing you're getting wrong. You should really consider reading
documentation;-)

Regards,
Leonard

Signature

Simplicity is the ultimate sophistication.
                                 -- Leonardo da Vinci

Jason Cavett - 25 Apr 2008 16:29 GMT
On Apr 25, 11:09 am, Leonard Milcin <leon...@milcin.dont-spam.pl>
wrote:
> > I'm trying to extract a ZIP file to a temporary directory
> > (System.getProperty("java.io.tmpdir")) and I keep getting the
[quoted text clipped - 34 lines]
> Simplicity is the ultimate sophistication.
>                                   -- Leonardo da Vinci

Actually, the issue was not as simple as what you suggested.

The problem is, I'm attempting to unzip a ZIP file.  I'm following the
tutorial found here: http://java.sun.com/developer/technicalArticles/Programming/compression/
and it works, except when there is a "path" value associated with the
entry.

This is what's causing the sticking point, and I'm not really sure how
to handle it.  I suppose I could parse the file name off the end of
the path (which I get through entry.getName()) and then create the
files using File.mkdirs(), but that seems too roundabout.

Is there something I'm missing at this point?  Like I said - it works
when there is no path value associated with the ZIP file.

Thanks
Leonard Milcin - 25 Apr 2008 16:42 GMT
> Actually, the issue was not as simple as what you suggested.
>
[quoted text clipped - 7 lines]
> the path (which I get through entry.getName()) and then create the
> files using File.mkdirs(), but that seems too roundabout.

You can't create file in a directory that doesn't exist. It has to be
created before you can create a file in it. File.mkdirs() is simplest
and for most cases best way to do it. And you can use File to parse
abstract paths (eg. to get the name of directory to be created).

> Is there something I'm missing at this point?  Like I said - it works
> when there is no path value associated with the ZIP file.

Because, then, you create the file in current directory.

Regards,
Leonard

Signature

Simplicity is the ultimate sophistication.
                                 -- Leonardo da Vinci



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.