Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

creation of new directory inside an exisiting directory  RSS feed

 
Ankit Chandrawat
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to write a file I/O code in which I need to create a subdirectory inside existing directories and then write a text file inside that new subdirectory created.



This is the code that I have written:



The issue is when I create directory ChatTranscripts manually, inside the path "D:/opt/jboss-4.0.3SP1/server/mercerhr/static_content/" the code runs fine but when I try to create it using the code above, it throws an error

java.io.FileNotFoundException: D:\opt\jboss-4.0.3SP1\server\mercerhr\static_content\ChatTranscripts\Mercer_Chat_1047835.txt (The system cannot find the path specified)

How can I ensure that the subdirectory ChatTranscripts gets created through Java code and hence the txt file inside it.
 
Paul Clapham
Sheriff
Posts: 22195
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To create a directory using Java code, use the mkdir() or mkdirs() method of the java.io.File class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!