1.常用构造函数
File file = new File(String pathName);
通过将给定路径名字符串转换为抽象路径名来创建一个新的File实例。
eg
String fromAddress = "D://TEST/HUAHAI/voice/";
File file = new File(fromAddress);
2.常用方法
(1)
eg
String[] holderFolderArr = file.list();
for(int i=0;i<holderFolderArr.length;i++){
String holderName = holderFolderArr[i];
}
(2)
eg
File backupFile = new File(backupVoicePath);
if (backupFile.exists()) {
deleteFile(backupVoicePath);
}
(3)
eg
public boolean deleteFile(String deleteFile) {
File path = new File(deleteFile);
if (!path.exists())
return false;
if (path.isFile()) {
path.delete();
return false;
}
File[] files = path.listFiles();
for (int i = 0; i < files.length; i++ ) {
deleteFile(files[i].getAbsolutePath());
}
path.delete();
return true;
}
(4)
eg
File destinationFolder = getDestinationFile(prcsNum,destination);
if (!destinationFolder.exists()) {
destinationFolder.mkdir();
}
(5)
eg
File[] voiceFiles = voiceFile.listFiles();
for (int k = 1; k <= voiceFiles.length; k++) {
String voiceFileName = voiceFiles[k-1].getName();
}