Skip to content

Instantly share code, notes, and snippets.

@alexejVasko
Created March 22, 2016 14:23
Show Gist options
  • Save alexejVasko/d472ff990c300cff7ad5 to your computer and use it in GitHub Desktop.
Save alexejVasko/d472ff990c300cff7ad5 to your computer and use it in GitHub Desktop.
package calculator;
import java.io.File;
import java.io.IOException;
public class FilePath {
public static void main(String[] args) {
try {
String filename = "output.txt";
String workingDirectory = System.getProperty("user.dir");
//****************//
String absoluteFilePath;
//absoluteFilePath = workingDirectory + System.getProperty("file.separator") + filename;
absoluteFilePath = workingDirectory + File.separator + filename;
System.out.println("Final filepath : " + absoluteFilePath);
//****************//
File file = new File(absoluteFilePath);
if (file.createNewFile()) {
System.out.println("File is created!");
} else {
System.out.println("File is already existed!");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment