boolean success = (new File("C:/temp/temp.txt")).delete();
if (success) {
// Deletion succeeded
}
Saturday, June 27, 2009
How to Get the Size of a File
6:42 PM
Posted by
Techsavy
File file = new File("C:/temp/temp.txt");
// Get the number of bytes in the file
long length = file.length();
// Get the number of bytes in the file
long length = file.length();
How to Determine If a File or Directory Exists
6:39 PM
Posted by
Techsavy
boolean existsFlag = (new File("C:/temp/temp.txt")).exists();
if (existsFlag) {
// File or directory exists
} else {
// File or directory does not exist
}
if (existsFlag) {
// File or directory exists
} else {
// File or directory does not exist
}
How to Create a File
6:37 PM
Posted by
Techsavy
try {
File file = new File("C:/temp/temp.txt");
} catch (IOException e) {
}
File file = new File("C:/temp/temp.txt");
} catch (IOException e) {
}
How to Determine If a File Path Is a File or a Directory
6:34 PM
Posted by
Techsavy
File file = new File("filepath");
boolean isDirectory = file.isDirectory();
if (isDirectory) {
// file is a directory
} else {
// file is a file
}
boolean isDirectory = file.isDirectory();
if (isDirectory) {
// file is a directory
} else {
// file is a file
}
How to Get an Absolute File Path
6:30 PM
Posted by
Techsavy
File file = new File("C:"+File.separatorChar+"temp"+File.separatorChar+"temp.txt");
file = file.getAbsoluteFile(); // c:\temp\temp.txt
file = file.getAbsoluteFile(); // c:\temp\temp.txt
How to Construct a File Path
6:23 PM
Posted by
Techsavy
String path = File.separator +"temp"; // /temp
Subscribe to:
Posts (Atom)