1. 读取文件变成字符数组
2. 字符数组循环替换a->A
3. 写入字符数组
public static void main(String[] args) throws Exception
{
File file1=new File("a.txt");
File file2=new File("b.txt");
FileReader fr=new FileReader(file1);
FileWriter fw=new FileWriter(file2);
char[] buf=new char[1024];
int len=fr.read(buf);
for(int i=0;i<len;i++)
{
if(buf[i]=='a')
buf[i]='A';
}
System.out.println(new String(buf));
fw.write(buf);
fw.flush();
} |