This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to create an un-existed path using stream Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How to create an un-existed path using stream" Watch "How to create an un-existed path using stream" New topic
Author

How to create an un-existed path using stream

chaohua wang
Ranch Hand

Joined: Dec 22, 2002
Posts: 62
Hi folks,

currently I can save file to an existed path.
like this
------------------------------------------------
String file=D:\\test\\test.txt

BufferedInputStream bistr = new BufferedInputStream(conn.getInputStream());

FileOutputStream fostr = new FileOutputStream(file);
BufferedOutputStream bostr = new BufferedOutputStream( fostr );

while(-1 != (bytesRead = bistr.read(buff, 0, buff.length)))
bostr.write(buff, 0, bytesRead);


----------------------------------------------------------------
currenlty the path D:\\test\\ existes.
I tried an an un-existed path, like D:\\test1\\
there is an error message: this path doesn't exist.
How can save it to an un-existed path?

Thank you.

Chaohua
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24081
    
  15

You have to create the directories first. See the "mkdir" and "mkdirs" methods of java.io.File.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create an un-existed path using stream
 
Similar Threads
Display PDF in IE from byte array using Servlet
Generating PDF and displaying it ...
how to download file from server through servlet
Corrupted Downloaded Files
Title as PDF file name