List of usage examples for java.io File getParent
public String getParent()
null
if this pathname does not name a parent directory. From source file:Main.java
public static boolean rename(File file, String name) { return file.renameTo(new File(file.getParent(), name)); }
From source file:Main.java
public static boolean isSymboliclink(File file) throws IOException { File canon;//from w w w.ja v a 2 s . com if (file.getParent() == null) { canon = file; } else { File canonDir = file.getParentFile().getCanonicalFile(); canon = new File(canonDir, file.getName()); } return !canon.getCanonicalFile().equals(canon.getAbsoluteFile()); }
From source file:Main.java
static File rename(File file, String newName) { File newFile = new File(file.getParent(), newName); if (!newFile.equals(file)) { if (newFile.exists()) { if (newFile.delete()) { Log.d("FileUtil", "Delete old " + newName + " file"); }/*from w w w .j a v a 2 s . co m*/ } if (file.renameTo(newFile)) { Log.d("FileUtil", "Rename file to " + newName); } } return newFile; }
From source file:Main.java
public static File rename(File file, String newName) { File newFile = new File(file.getParent(), newName); if (!newFile.equals(file)) { if (newFile.exists()) { newFile.delete();/* w w w. ja va 2s .c o m*/ } file.renameTo(newFile); } return newFile; }
From source file:Main.java
public static File rename(File file, String newName) { File newFile = new File(file.getParent(), newName); if (!newFile.equals(file)) { if (newFile.exists()) { if (newFile.delete()) { }/*from w w w . j a v a2 s.c o m*/ } if (file.renameTo(newFile)) { } } return newFile; }
From source file:com.alibaba.zonda.logger.server.util.FileUtil.java
public static boolean rename(File f1, File f2) { ensurePathExists(f2.getParent()); if (f2.exists()) f2.delete();/* ww w .j a v a 2 s . c o m*/ return f1.renameTo(f2); }
From source file:Main.java
static String getParentPath(String path) { File file = new File(path); String parent = file.getParent(); if (parent == null) { File[] roots = File.listRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].equals(file)) { parent = getRootDirectoryPath(); break; }/* w w w .j av a 2s. c o m*/ } } return parent; }
From source file:AIR.Common.Utilities.Path.java
public static String getDirectoryName(String path) { if (StringUtils.endsWith(path, "/") || StringUtils.endsWith(path, "\\")) return path.substring(0, path.length() - 1); File f = new File(path); return f.getParent(); }
From source file:Main.java
public static File getSignatureDirectoryForFile(File originalFile) { return new File(originalFile.getParent() + File.separatorChar + MARTUS_SIGNATURE_FILE_DIRECTORY_NAME); }
From source file:Main.java
public static void saveToFile(String fileName, String str) throws IOException { File f = new File(fileName); if (!f.exists()) { if (f.getParent() != null) { new File(f.getParent()).mkdirs(); }/*from w w w . ja va2 s . c om*/ f.createNewFile(); } FileWriter fw = new FileWriter(f); fw.write(str); fw.close(); }