.net - Create a file from a path, creating subdirectories if they not exists -



.net - Create a file from a path, creating subdirectories if they not exists -

in config of app i've path, illustration "logs\updater\updater.log"

starting app, want create file updater.log, creating subfolders if not exists.

so, if tomorrow user changes path in config "logs\mypathisbetter\updater.log", app continues work, writing log new file.

file.create, fileinfo.create, streamwriter.create or so: that?

or need check if folders exists, before?

i can't find clear reply question on net.

no, don't seem - you'll directorynotfoundexception, believe three.

you need directory.createdirectory(path) first.

edit:

for bit more of total solution starts path including filename, try:

directory.createdirectory(path.getdirectoryname(fullpath)); textwriter author = new streamwriter(fullpath); writer.writeline("hello mum"); writer.close();

but bear in mind you'll need error handling too, author gets closed (in 'finally' block).

.net file

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -