我有一个查询,请参阅下面的代码:
public void readFile(String path,String pathName,int num){
try{
PrintWriter out2=new PrintWriter(new PrintWriter(path));
File a=new File(pathName);
Scanner b=new Scanner(a);
while(b.hasNextLine()){
String message=b.nextLine();
Scanner h=new Scanner(message);
while(h.hasNext()){
String f=h.next();
if (f.equals("are")){
f.replace("are","ARE");
}
}
out2.printf("%s",message);
out2.println();
.......
扫描仪读取的文件内容是
who are you?
how are you?
what is up!
但是,当我运行上述代码时,新文件的输出与输入文件相同,这意味着“are”没有被“ARE”替换,我不知道哪个部分错了,请指教,谢谢!