1.判断文件是否存在
public static boolean isExists(String filePath, String fileName) {
if (!filePath.endsWith("\\") || !filePath.endsWith("/")) {
filePath += "\\";
}
return isExists(filePath + fileName);
}
public static boolean isExists(String fileFullName) {
File file = new File(fileFullName);
if (!file.exists()) {
return false;
}
return true;
}
public static File writeFileContent(String fileFullName, String strContent) {
File file = new File(fileFullName);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
if (!StringUtil.isEmpty(strContent)) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
byte[] contentInBytes = strContent.getBytes();
fos.write(contentInBytes);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (null != fos) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
return file;
}