FileWriter not writing into directory properly - java

I have a simple program that reads in commands and performs them. Rightnow I have this code for inserting certain text into a text file:
Example command:
INSERT "John Smith" INTO college.student
My main method:
else if(command.substring(0,6).equalsIgnoreCase("INSERT")){
String string = command.substring(7, command.indexOf("INTO") - 1);
String DBNameTBName = command.substring(command.indexOf("INTO") + 5);
String tableName = DBNameTBName.substring(DBNameTBName.indexOf(".") + 1);
String DBName = DBNameTBName.substring(0, DBNameTBName.indexOf("."));
if(DBCommands.insert(string, DBName, tableName)){
statfileWriter.println("Inserted " + string + " into table " + tableName + " in " + DBName);
statfileWriter.println("(" + command + ")");
statfileWriter.flush();
}
else{
errfileWriter.println("Error: Could not insert " + string + " into table " + tableName + " in " + DBName);
errfileWriter.println("(" + command + ")");
errfileWriter.flush();
}
And the insert method it calls:
public static boolean insert(String string, String DBName, String tableName){
try{
string = string.substring(string.indexOf('"') + 1, string.lastIndexOf('"')); //removes quotes
File tableToWriteTo = new File(DBName + "/" + tableName + ".txt");
if (!tableToWriteTo.exists()){
return false;
}
PrintWriter writer = new PrintWriter(new FileWriter
(tableToWriteTo, true));
writer.println(string);
writer.close();
return true;
}
catch(Exception e){
return false;
}
}
I am getting very weird behavior with my insert method. It returns true as it always prints to my status log and not error log. I know the method to create the .txt file is working perfectly, I have tested it many times and the student.txt file is always there. With my insert command, if I change the File = new File line to this:
File tableToWriteTo = new File(tableName + ".txt");
Then it unsurprisingly creates a .txt file called "student" with my example command, but not in the "DBName" folder. If I change it to this:
File tableToWriteTo = new File(DBName + "/" + tableName);
Then it creates a file called "student" with no type (as in, Windows asks what I want to open it with) but puts in the string I want to insert into it. I should note that if there are multiple INSERT commands then it writes all the strings as I would like it to.
I have tried declaring PrintWriter and File in my main method and passing them in, but that doesn't work either.
How can I get it to write into students.txt in the directory college?
EDIT: Oh my goodness, I'm the stupidest person on Earth. I didn't look at the full commands list I received for this assignment and I forgot there was a delete command and they were BOTH working. I would delete this question but I'll leave this up in case anyone in the future wants to see an example of FileWriter.

I changed the if condition in the insert method. The file is not expected to exist. So ideally the condition should not be negated. I used the following code and it is working for me.
public class InsertToWriteTo {
public static void main(String[] args) {
boolean ret = insert("\"hello\"", "college", "student");
System.out.println(ret);
}
public static boolean insert(String string, String DBName, String tableName) {
try {
string = string.substring(string.indexOf('"') + 1, string.lastIndexOf('"')); // removes quotes
File tableToWriteTo = new File(DBName + "/" + tableName + ".txt");
if (tableToWriteTo.exists()) { // changed condition
System.out.println("File exists");
return false;
}
PrintWriter writer = new PrintWriter(new FileWriter(tableToWriteTo, true));
writer.println(string);
writer.close();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
Hope this helps!

Related

Running multiple Batch files from different threads Java

I have n number of thread getting created at run time according to the input source files present in a folder. For every thread, I have one common class which has all the functions present that are used by every thread. Every thing is working perfectly except the part where batch files are run.
I have main class which is creating thread(which is working perfectly fine). Then I am creating batch files with relevant contents( which is also running perfectly). After that, only 1(can be anyone, no specific pattern) thread is able to execute the batch file and not the others.
Code:
String batch_content = "echo off \n "
+ "powershell.exe -file "
+ utility_path + "convertCSVSwiss.ps1 " + fpath + filename + " -executionpolicy Unrestricted \n ";
String batch_name = "batch_" + fname +"_"+sdf.format(cal.getTime())+ ".bat";
Utils.createBatchFile(batch_content, bat_file_path, batch_name);
Utils.RunBatch(bat_file_path, batch_name,csv_file_path,fname);
Utils.createBatchFile is working fine which create a batch file with the batch content. But Utils.RunBatch seems to having some problem. Here is the code for RunBatch:
public static void RunBatch(String filepath, String filename,String csv_file_path,String fname) throws Exception {
try {
System.out.println("Started Program");
new File(csv_file_path + "\\" + fname).mkdir();
String filePath1 = filepath + filename;
System.out.println("Batch file running is " + filePath1);
Process p = Runtime.getRuntime().exec(new String[] { "cmd.exe", "/c", filePath1 });
p.getOutputStream().close();
p.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
}
My log file prints this:
Batch file running is C:\ER\ETL\bat files\batch_Sample_Data_10_40_16_12_40_37.bat
Batch file running is C:\ER\ETL\bat files\batch_ssd_10_40_16_12_40_37.bat
but it runs only the first one.
Any help would be appreciated.
P.S I am sorry if I missed any information that may be necessary to get this problem resolved. Please let me know and I can then edit my post.
EDIT:
Here is my code.
//main class to start new thread for every excel file present in the source directory
public class LoadData{
public static void main(String[] args) throws Exception{
try{
File folder = new File(fpath);
File[] listoffiles = folder.listFiles();
for (int i = 0; i < listoffiles.length; i++) {
if (listoffiles[i].isFile()) {
filename = listoffiles[i].getName();
c = filename.lastIndexOf(".");
absfilename = filename.substring(0, c);
System.out.println("File name with extension is "+filename);
System.out.println("File name is "+absfilename);
System.out.println("Starting thread for "+absfilename);
ConvertToCSV et = new ConvertToCSV();
et.fpath = fpath;
et.utility_path=utility_path;
et.filename=filename;
et.fname = absfilename;
et.bat_file_path =bat_file_path;
et.tpath =tpath;
et.csv_file_path=csv_file_path;
Thread t = new Thread(et);
t.start();
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
//class to create the batch file content
public class ConvertToCSV implements Runnable{
String fpath,utility_path,filename,fname,bat_file_path,tpath,csv_file_path;
try{
String batch_content = "echo off \n "
+ "powershell.exe -file "
+ path_to_powershell_script_to_convert_excel_into_csv + "convertCSVSwiss.ps1 " + path_and_name_to_the_excel_file " -executionpolicy Unrestricted \n ";
String batch_name = "batch_" + excel_file_name +"_"+sdf.format(cal.getTime())+ ".bat";
Utils.createBatchFile(batch_content, bat_file_path, batch_name);
Utils.RunBatch(bat_file_path, batch_name,csv_file_path,fname);
}
catch (Exception e) {
e.printStackTrace();
}
}
public class Utils{
//function to create the batch file
public static void createBatchFile(String batch_content, String path, String batch_name) throws IOException {
String p = path + batch_name;
File batfile = new File(p);
FileWriter fw = new FileWriter(batfile);
fw.write(batch_content);
fw.close();
}
//function to run the batch file
public static void RunBatch(String filepath, String filename,String csv_file_path,String fname) throws Exception {
try {
System.out.println("Started Program");
new File(csv_file_path + "\\" + fname).mkdir();
String filePath1 = filepath + filename;
System.out.println("Batch file running is " + filePath1);
Process p = Runtime.getRuntime().exec(new String[] { "cmd.exe", "/c", filePath1 });
p.getOutputStream().close();
p.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
}
}
EDIT2: I have added the run for ConvertTO CSV. My code is doing say 10 things, and 9 of them are working fine except running two batch files with different names from the same folder
public class ConvertToCSV implements Runnable{
String fpath,utility_path,filename,fname,bat_file_path,tpath,csv_file_path,pg_db_url,pg_db,pg_db_uid,pg_db_pwd,plpgsql_path,Log_Path;
SimpleDateFormat sdf = new SimpleDateFormat("dd_mm_yy_hh_mm_ss");
Calendar cal = Calendar.getInstance();
#Override
public void run() {
try {
runConvertToCSV(fpath,utility_path,filename,fname,bat_file_path,tpath,csv_file_path,plpgsql_path);
} catch (Exception e) {
e.printStackTrace();
}
}
private void runConvertToCSV(String fpath,String utility_path,String filename,String fname,String bat_file,String tpath,String csv_file_path,String plpgsql_path) throws Exception{try{
String batch_content = "echo off \n "
+ "powershell.exe -file "
+ path_to_powershell_script_to_convert_excel_into_csv + "convertCSVSwiss.ps1 " + path_and_name_to_the_excel_file " -executionpolicy Unrestricted \n ";
String batch_name = "batch_" + excel_file_name +"_"+sdf.format(cal.getTime())+ ".bat";
Utils.createBatchFile(batch_content, bat_file_path, batch_name);
Utils.RunBatch(bat_file_path, batch_name,csv_file_path,fname);
}
catch (Exception e) {
e.printStackTrace();
}
}
EDIT3#:
My guess was that maybe because all the batch files are trying to access the same powershell script, that is why it is not working. But then i created ps script for every batch file. Also, added error stream to the stdout to check if there is any error and this is what i am getting:
Standard Error:
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\ER\ETL\ETL_SOURCE\convertCSVSwiss_Swiss_Sample_Data.ps1:24 char:2
+ $Worksheet.SaveAs($ExtractedFileName,6)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
there are number of same error at different line. NOTE: It is the same ps script for all the batch files, it runs only for one and not for others. and that one can be anyone(no pattern).
If i run the above batch file manually, then it succeeds.

Writing data to a txt file file using java classes

I am trying to understand why my code is not writing the output to the textfile as I expect it to work. My program takes a filename as a command line argument, and prints some text to the file as well as the screen. It is a bit more complicated since it uses classes and objects to demonstrate how objects work. Can anyone help decipher why it is not writing to the file? Here's my code:-
public class Mamoonp3test {
public static void main(String[] args) throws Exception {
//Create array of 10 guitar (Mamoonp3) objects
final int NUMBER_OF_INSTANCES = 10;
Mamoonp3[] objectNames = new Mamoonp3[NUMBER_OF_INSTANCES];
try
{
String fileName = new String(args[0]);
for(int i=0; i<NUMBER_OF_INSTANCES; i++) {
objectNames[i] = new Mamoonp3(FileName);
System.out.println("This is guitar number: " + i);
objectNames[i].tuneGuitar();
objectNames[i].playGuitar();
objectNames[i].displayAcronym();
objectNames[i].stopGuitar();
System.out.println("---------------------------");
}
}
catch (Exception e)
{
System.out.println("please provide an input file");
System.out.println("Usage: java Mamoonp3test filename.txt");
}
}
}
import java.io.*;
public class Mamoonp3 {
final int NUMBER_OF_STRINGS = 6;
char[] stringNames = {'E','A','D','G','B','E'};
int[] stringNumbers = {6,5,4,3,2,1};
String[] stringPitch = {"Sixth","Fifth","Fourth","Third","Second","First"};
boolean isTuned;
boolean isPlaying;
String stringAcronym = new String("Even After Dinner Giant Boys Eat");
//create a PrintWriter for output
PrintWriter output;
public Mamoonp3(String fileName) throws Exception{
isTuned = false;
isPlaying = false;
// create target file
File targetFile = new File(fileName);
//create a PrintWriter for output
output = new PrintWriter(targetFile);
}
public void tuneGuitar() {
System.out.println("The guitar is now tuned.");
for (int i=0; i<NUMBER_OF_STRINGS; i++) {
System.out.println(stringNames[i] + " is string number " + stringNumbers[i] + " and ranked " + stringPitch[i] + " in pitch");
output.print(stringNames[i] + " is string number " + stringNumbers[i] + " and ranked " + stringPitch[i] + " in pitch");
output.close();
}
}
public void playGuitar() {
System.out.println("The guitar is now playing.");
output.print("The guitar is now playing.");
output.close();
}
public void stopGuitar() {
System.out.println("The guitar is now stoped.");
output.print("The guitar is now stoped.");
output.close();
}
public void displayAcronym() {
System.out.println("Always remember your string names!");
System.out.println("Heres a reminder: " + stringAcronym);
output.print("Always remember your string names!");
output.print("Heres a reminder: " + stringAcronym);
output.close();
}
}
You're setting the File of an object that you then do nothing with, that you're not writing with,
Mamoonp3 newObject = new Mamoonp3(fileName);
... and not setting the File in objects that you try to write with. Check which constructors you are using: every Manoop3 object created in the for loop. To see that this is so, check which constructors you're using
I suggest that you change your approach entirely.
Get all file input and output out of your Mamoonp3 class.
Instead, that class should concern itself with representing the state of the musical instrument, and nothing else.
Give the class a decent toString() override method.
I & O should go elsewhere in a separate class of its own.
Give your I&O class a method that allows you to pass Mamoonp3 objects into it so that they can be written.
As an aside, you almost never would use new String(anything). Just use args[0].
Always close your PrintWriter when you are done writing. This is likely causing your error.
Edit
Possibly another way to solve this:
Create a PrintWriter object in the main method.
Give your Manoop3 class a PrintWriter field and a constructor that takes this PrintWriter and sets its field with it.
Write with the PrintWriter in Manoop3, but don't close it.
Then close the PrintWriter in the main method when all Manoop3 objects have completed their use of it.

Simple Backup and Restore for mysql Database from Java

How to backup a mysql database from a java code such that:
It's saving path is dynamically allocated.
Spaces in Path do not create problems.
Path is generated using the executing jar file.
DBname,DBusername or DBpass are dynamically allotted.
Creating a specialized folder to save the backup file.
Note: The codes given below are one way of solving the problem and probably not the best method. Everything is changeable inside the code. If you do not have mysql in environment variables, add the path before mysqldump and mysql (e.g. For XAMPP, C:\xampp\mysql\bin\mysqldump)
(Hope, this will solve your problems. Took me a day to completely figure out everything and implement them properly)
Method for Backup:
public static void Backupdbtosql() {
try {
/*NOTE: Getting path to the Jar file being executed*/
/*NOTE: YourImplementingClass-> replace with the class executing the code*/
CodeSource codeSource = YourImplementingClass.class.getProtectionDomain().getCodeSource();
File jarFile = new File(codeSource.getLocation().toURI().getPath());
String jarDir = jarFile.getParentFile().getPath();
/*NOTE: Creating Database Constraints*/
String dbName = "YourDBName";
String dbUser = "YourUserName";
String dbPass = "YourUserPassword";
/*NOTE: Creating Path Constraints for folder saving*/
/*NOTE: Here the backup folder is created for saving inside it*/
String folderPath = jarDir + "\\backup";
/*NOTE: Creating Folder if it does not exist*/
File f1 = new File(folderPath);
f1.mkdir();
/*NOTE: Creating Path Constraints for backup saving*/
/*NOTE: Here the backup is saved in a folder called backup with the name backup.sql*/
String savePath = "\"" + jarDir + "\\backup\\" + "backup.sql\"";
/*NOTE: Used to create a cmd command*/
String executeCmd = "mysqldump -u" + dbUser + " -p" + dbPass + " --database " + dbName + " -r " + savePath;
/*NOTE: Executing the command here*/
Process runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
/*NOTE: processComplete=0 if correctly executed, will contain other values if not*/
if (processComplete == 0) {
System.out.println("Backup Complete");
} else {
System.out.println("Backup Failure");
}
} catch (URISyntaxException | IOException | InterruptedException ex) {
JOptionPane.showMessageDialog(null, "Error at Backuprestore" + ex.getMessage());
}
}
Method for Restore:
public static void Restoredbfromsql(String s) {
try {
/*NOTE: String s is the mysql file name including the .sql in its name*/
/*NOTE: Getting path to the Jar file being executed*/
/*NOTE: YourImplementingClass-> replace with the class executing the code*/
CodeSource codeSource = YourImplementingClass.class.getProtectionDomain().getCodeSource();
File jarFile = new File(codeSource.getLocation().toURI().getPath());
String jarDir = jarFile.getParentFile().getPath();
/*NOTE: Creating Database Constraints*/
String dbName = "YourDBName";
String dbUser = "YourUserName";
String dbPass = "YourUserPassword";
/*NOTE: Creating Path Constraints for restoring*/
String restorePath = jarDir + "\\backup" + "\\" + s;
/*NOTE: Used to create a cmd command*/
/*NOTE: Do not create a single large string, this will cause buffer locking, use string array*/
String[] executeCmd = new String[]{"mysql", dbName, "-u" + dbUser, "-p" + dbPass, "-e", " source " + restorePath};
/*NOTE: processComplete=0 if correctly executed, will contain other values if not*/
Process runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
/*NOTE: processComplete=0 if correctly executed, will contain other values if not*/
if (processComplete == 0) {
JOptionPane.showMessageDialog(null, "Successfully restored from SQL : " + s);
} else {
JOptionPane.showMessageDialog(null, "Error at restoring");
}
} catch (URISyntaxException | IOException | InterruptedException | HeadlessException ex) {
JOptionPane.showMessageDialog(null, "Error at Restoredbfromsql" + ex.getMessage());
}
}
If Hibernate is configured properly, this is cake:
Session session = HibernateUtil.getSessionFactory().openSession();
// for every table, have the bean implement Serializable and use the next 4 lines
List <TblBean> tblCollection = session.createCriteria(TblBean.class).list();
FileOutputStream backup = new FileOutputStream("backupOf"+TblBean.getClass().getName()+".dat");
ObjectOutputStream backupWriter = new ObjectOutputStream(backup);
backupWriter.write(tblCollection);
public static String getData(String host, String port, String user, String password, String db,String table) throws Exception {
//an "C:/xampp/mysql/bin/mysqldump" ---- location ito han mysqldump
Process run = Runtime.getRuntime().exec(
"C:/xampp/mysql/bin/mysqldump --host=" + host + " --port=" + port +
" --user=" + user + " --password=" + password +
" --compact --databases --add-drop-table --complete-insert --extended-insert " +
"--skip-comments --skip-triggers "+ db+" --tables "+table);
InputStream in = run.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
StringBuffer temp = new StringBuffer();
int count;
char[] cbuf = new char[BUFFER];
while ((count = br.read(cbuf, 0, BUFFER)) != -1)
temp.append(cbuf, 0, count);
br.close();
in.close();
return temp.toString();
}
In addition to chettyharish's answer, if your server os is ubuntu the path should have front slash '/' instead of backslash '\' such as /path/to/your/file
For example: String savePath = "\"" + jarDir + "\\backup\\" + "backup.sql\"";
Will be : String savePath="/"+jarDir+"/backup/backup.sql"

InputStream is null

In a program I'm working on I have
String cwd;
String file_separator;
public ConfigLoader()
{
cwd = get_cwd();
file_separator = get_file_separator();
try
{
Properties c = new Properties();
InputStream in = this.getClass().getClassLoader().getResourceAsStream(cwd +
file_separator + "data" + file_separator + "configuration.properties");
c.load(in);
}
except (Exception e) { e.printStackTrace(); }
}
public String get_file_separator()
{
File f = new File("");
return f.separator;
}
public String get_cwd()
{
File cwd = new File("");
return cwd.getAbsolutePath();
}
For some reason, though, c.load(in); causes a NullPointerException. The exception comes from in == NULL being true. I can't figure out why because
System.out.println(cwd + file_separator + "data" + file_separator +
"configuration.properties");
prints
/users/labnet/st10/jjb127/workspace/Brewer-Client/data/configuration.properties
which is the location of the file I'm wanting to use.
Thoughts?
getResourceAsStream is meant to search for files on the classpath and not for accessing the local file system. You will have to use FileInputStream for this case.
InputStream in = new FileInputStream(cwd +
file_separator + "data" + file_separator + "configuration.properties");

Java writing to a text file not working properly

The Java application that I support is logging some details in a flat file. the problem I face some times is that, the entry is very low compared to the previous day. This entry is most essential because our reports are generated based on the file. I went thro code for writing I couldn't figure out any issues. the method which is writing is sync method.
Any suggestions? I can also provide the code for you is you may need?
public synchronized void log (String connID, String hotline, String callerType,
String cli, String lastMenu, String lastInput,
String status, String reason)
{
//String absoluteFP = LOG_LOC + ls + this.getFilename();
//PrintWriter pw = this.getPrintWriter(absoluteFP, true, true);
try
{
pw.print (this.getDateTime ()+ ","+connID +","+hotline+","+callerType+","+ cli+"," + lastMenu + "," + lastInput + "," + status + "," + reason);
//end 1006
pw.print (ls);
pw.flush ();
//pw.close();
}
catch (Exception e)
{
e.printStackTrace ();
return;
}
}
private synchronized PrintWriter getPrintWriter (String absoluteFileName,
boolean append, boolean autoFlush)
{
try
{
//set absolute filepath
File folder = new File (absoluteFileName).getParentFile ();//2009-01-23
File f = new File (absoluteFileName);
if (!folder.exists ())//2009-01-23
{
//System.out.println ("Call Detailed Record folder NOT FOUND! Creating a new);
folder.mkdirs ();
//System.out.println ("Configure log folder");
this.setHiddenFile (LOG_LOC);//set tmp directory to hidden folder
if (!f.exists ())
{
//System.out.println ("Creating a new Call Detailed Record...");//2009-01-23
f.createNewFile ();//2009-01-23
}
}
else
{
if (!f.exists ())
{
//System.out.println ("Creating a new Call Detailed Record...");//2009-01-23
f.createNewFile ();//2009-01-23
}
}
FileOutputStream tempFOS = new FileOutputStream (absoluteFileName, append);
if (tempFOS != null)
{
return new PrintWriter (tempFOS, autoFlush);
}
else
{
return null;
}
}
catch (Exception ex)
{
ex.printStackTrace ();
return null;
}
}
/**
* Set the given absolute file path as a hidden file.
* #param absoluteFile String
*/
private void setHiddenFile (String absoluteFile)
{
//set hidden file
//2009-01-22, KC
Runtime rt = Runtime.getRuntime ();
absoluteFile = absoluteFile.substring (0, absoluteFile.length () - 1);//2009-01-23
try
{
System.out.println (rt.exec ("attrib +H " + "\"" + absoluteFile + "\"").getInputStream ().toString ());
}
catch (IOException e)
{
e.printStackTrace ();
}
}
private String getDateTime ()
{
//2011-076-09, KC-format up to milliseconds to prevent duplicate PK in CDR table.
//return DateUtils.now ("yyyy/MM/dd HH:mm:ss");
return DateUtils.now ("yyyy/MM/dd HH:mm:ss:SSS");
//end 0609
}
private String getFilename ()
{
///return "CDR_" + port + ".dat";//2010-10-01
return port + ".dat";//2010-10-01
}
public void closePW ()
{
if (pw != null)
{
pw.close ();
}
}
You've created a FileOutputStream, but aren't closing that stream. Close that stream and try again. That might be causing the problem.
Messages are getting logged sometime because the garbage collector kicks in at some intervals and closes the FileOutStream. This then allows messages to be logged again. You're getting the unreachable error since you have a return statement in both the if & else blocks. You'll have to take the PrintWriter and FileOutStreamWriter out of the getPrintWriter put it where you usually call the getPrintWriter(). Then you'll be able to close the streams correctly. getPrintWriter should only ensure file exists, so rename it to ensureFileExistance
If you can use Apache Common IO, try this:
public synchronized void log(String connID, String hotline, String callerType,
String cli, String lastMenu, String lastInput,
String status, String reason) {
String absoluteFP = LOG_LOC + ls + this.getFilename();
File file = new File(absoluteFP);
String message = this.getDateTime() + "," + connID + "," + hotline + "," + callerType + "," + cli + "," + lastMenu + "," + lastInput + "," + status + "," + reason;
try {
// note that you must explicitly add new line character if you want the line to end with newline
FileUtils.write(file, message + "\n", "UTF-8", true);
} catch (IOException ex) {
ex.printStackTrace ();
}
}
In Common IO 2.1, you can append a file that you are writting to. You can now get rid of the closePW and getPrintwriter and since the log method is synchronized, the file can be written one at a time from the same object. However, if you try to write the same file from different object at the same time, you will end up having overwritting problem.
Also, Common IO create the missing parent folder for you automatically. There is no need to explicitly check and create the folder.

Categories

Resources