- 目录结构
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/aa33418e039f212d0c2c20a20d7e4923.png)
- FileIO 代码
package readFile;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
public class FileIO {
public String readFile(String filePath) {
Reader fr = null;
StringBuffer sb = new StringBuffer();
try {
fr = new FileReader(filePath);
char ch[] = new char[1024];
int length = 0;
length = fr.read(ch);
while (length != -1) {
sb.append(ch);
length = fr.read(ch);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (null != fr)
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
public void writeFile(String filePath, String str) {
Writer fw = null;
try {
fw = new FileWriter(filePath