Create A Directory If It Does Not Exist And Then Create The Files In That Directory As Well
Answer : This code checks for the existence of the directory first and creates it if not, and creates the file afterwards. Please note that I couldn't verify some of your method calls as I don't have your complete code, so I'm assuming the calls to things like getTimeStamp() and getClassName() will work. You should also do something with the possible IOException that can be thrown when using any of the java.io.* classes - either your function that writes the files should throw this exception (and it be handled elsewhere), or you should do it in the method directly. Also, I assumed that id is of type String - I don't know as your code doesn't explicitly define it. If it is something else like an int , you should probably cast it to a String before using it in the fileName as I have done here. Also, I replaced your append calls with concat or + as I saw appropriate. public void writeFile(String value){ String PATH = "/remote/dir/server/"; ...