• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can I create a new file with a directory?

 
James Lumei
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Another question. Can I create a new file and a directory at the same time? For example, my current working directory is D:\working, then I want to create a file named logFile.log and want to put it to the 'logs' subdirectory of the working directory ('logs' subdirectory does not exist.). I try this 'File logFile = new File("D:\\working\\logs\\logFile.log")' in WinNT, and then use 'logFile.createNewFile()' to get the file but always give me an exception.
How can I create a file with some level directories at the same time?
thank you,
James
 
moazzam rasheed
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well first of all u will have to make a sub driectory
likke if u want to write in
c:/working/log/logfile.txt
and u have only directory existing c:/working
u will have to do
File subDir = new File("C:/working/", "log" );
if(subDir.isDirectory() == false)
subDir.makeDirectory();
or makeDir plz confirm ...........
then write file in that directory
then u will noy have any exception
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!