• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create an un-existed path using stream  RSS feed

 
chaohua wang
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to create the directories first. See the "mkdir" and "mkdirs" methods of java.io.File.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!