List of usage examples for java.io File getPath
public String getPath()
From source file:GuaranteeAFile.java
public static void main(String[] args) { String filename = "C:/myFile.txt"; File aFile = new File(filename); if (aFile.isDirectory()) { System.out.println("The path " + aFile.getPath() + " does not specify a file. Program aborted."); System.exit(1);//from ww w. j ava2 s .c om } if (!aFile.isFile()) { aFile = aFile.getAbsoluteFile(); File parentDir = new File(aFile.getParent()); if (!parentDir.exists()) { parentDir.mkdirs(); } } FileOutputStream outputFile = null; try { outputFile = new FileOutputStream(aFile, true); } catch (FileNotFoundException e) { e.printStackTrace(System.err); } }
From source file:FileDemo.java
public static void main(String args[]) { File f1 = new File("/java/COPYRIGHT"); System.out.println("File Name: " + f1.getName()); System.out.println("Path: " + f1.getPath()); System.out.println("Abs Path: " + f1.getAbsolutePath()); System.out.println("Parent: " + f1.getParent()); System.out.println(f1.exists() ? "exists" : "does not exist"); System.out.println(f1.canWrite() ? "is writeable" : "is not writeable"); System.out.println(f1.canRead() ? "is readable" : "is not readable"); System.out.println("is " + (f1.isDirectory() ? "" : "not" + " a directory")); System.out.println(f1.isFile() ? "is normal file" : "might be a named pipe"); System.out.println(f1.isAbsolute() ? "is absolute" : "is not absolute"); System.out.println("File last modified: " + f1.lastModified()); System.out.println("File size: " + f1.length() + " Bytes"); }
From source file:Main.java
public static void main(String[] args) throws Exception { File file = null; File dir = new File("C:/"); file = File.createTempFile("JavaTemp", ".javatemp", dir); System.out.println(file.getPath()); }
From source file:MainClass.java
public static void main(String[] a) { File myFile = new File("C:" + File.separator + "jdk1.5.0" + File.separator, "File.java"); System.out.println(myFile.getName()); System.out.println(myFile.getPath()); }
From source file:com.github.rinde.gpem17.Train.java
public static void main(String[] args) { if (args.length == 0) { run("files/config/gpem17.params"); } else {/* w w w. ja v a 2s. c om*/ for (String file : args) { File f = new File(file); if (f.isDirectory()) { File[] paramFiles = f.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".params"); } }); Arrays.sort(paramFiles, new Comparator<File>() { @Override public int compare(File o1, File o2) { return o1.getName().compareTo(o2.getName()); } }); for (File paramFile : paramFiles) { run(paramFile.getPath()); } } else { run(file); } } } }
From source file:Main.java
public static void main(String[] args) { File f = new File("c:/test.txt"); boolean bool = f.exists(); if (bool) {/*from w ww. j a v a2 s.c o m*/ long len = f.length(); String path = f.getPath(); System.out.print(path + " file length: " + len); } }
From source file:MainClass.java
public static void main(String args[]) { File f1 = new File("MainClass.java"); System.out.println("File Name:" + f1.getName()); System.out.println("Path:" + f1.getPath()); System.out.println("Abs Path:" + f1.getAbsolutePath()); System.out.println("Parent:" + f1.getParent()); System.out.println(f1.exists() ? "exists" : "does not exist"); System.out.println(f1.canWrite() ? "is writeable" : "is not writeable"); System.out.println(f1.canRead() ? "is readable" : "is not readable"); System.out.println("is a directory" + f1.isDirectory()); System.out.println(f1.isFile() ? "is normal file" : "might be a named pipe"); System.out.println(f1.isAbsolute() ? "is absolute" : "is not absolute"); System.out.println("File last modified:" + f1.lastModified()); System.out.println("File size:" + f1.length() + " Bytes"); }
From source file:Main.java
public static void main(String[] args) { // create new file File f = new File("c:/test.txt"); // true if the file path is a hidden file boolean bool = f.isHidden(); // get the path String path = f.getPath(); System.out.print(path + " is file hidden? " + bool); }
From source file:fr.gael.dhus.database.util.RestoreDatabase.java
/** * @param args// ww w .j a v a 2 s.c om * @throws IllegalAccessException * @throws IOException */ public static void main(String[] args) throws IllegalAccessException, IOException { if (args.length != 2) { throw new IllegalArgumentException(RestoreDatabase.class.getCanonicalName() + ": Wrong arguments <source path> <destination path>."); } File dump = new File(args[0]); File db = new File(args[1]); logger.info("Restoring " + dump.getPath() + " into " + db.getPath() + "."); if (!db.exists()) throw new IllegalArgumentException(RestoreDatabase.class.getCanonicalName() + ": Input database path not found (\"" + db.getPath() + "\")."); if (!dump.exists()) throw new IllegalArgumentException(RestoreDatabase.class.getCanonicalName() + ": Input database dump path not found (\"" + db.getPath() + "\")."); FileUtils.deleteDirectory(db); FileUtils.copyDirectory(dump, db); logger.info("Dump properly restored, please restart system now."); }
From source file:Main.java
public static void main(String[] args) throws Exception { File file1 = null; File file2 = null;//from www . j a v a 2 s. c o m file1 = File.createTempFile("JavaTemp", null); file2 = File.createTempFile("JavaTemp", ".java"); System.out.println(file1.getPath()); System.out.println(file2.getPath()); }