java文件IO操作
[java]package com.io;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.PrintWriter;
public class FileOperate {
/**
* 新建目录
* @param folderPath String 如 c:/fqf
* @return boolean
*/
public static void newFolder(String folderPath) {
try {
String filePath = folderPath;
File myFilePath = new File(filePath);
if (!myFilePath.exists()) {
myFilePath.mkdir();
}
}
catch (Exception e) {
System.out.println("新建目录操作出错");
e.printStackTrace();
}
}
/**
* 新建文件
* @param filePathAndName String 文件路径及名称 如c:/fqf.txt
* @param fileContent String 文件内容
* @return boolean
*/
public static void newFile(String filePathAndName, String fileContent) {
try {
String filePath = filePathAndName;
File myFilePath = new File(filePath);
if (!myFilePath.exists()) {
myFilePath.createNewFile();
System.out.println("创建文件成功");
}
FileWriter resultFile = new FileWriter(myFilePath);
PrintWriter myFile = new PrintWriter(resultFile);
myFile.println(fileContent);
System.out.println("写入文件成功");
resultFile.close();
}
catch (Exception e) {
System.out.println("新建文件操作出错");
e.printStackTrace();
}
}
/**
* 删除文件
* @param filePathAndName String 文件路径及名称 如c:/fqf.txt
* @param fileContent String
* @return boolean
*/
public static void delFile(String filePathAndName) {
try {
File myDelFile = new File(filePathAndName);
myDelFile.delete();
System.out.println("删除文件成功!");
}
catch (Exception e) {
System.out.println("删除文件操作出错");
e.printStackTrace();
}
}
/**
&
补充:软件开发 , Java ,