Java 文件大小不断增加
在执行下面的代码时,设备上“username.txt”文件的大小不断增加。原因是什么Java 文件大小不断增加,java,Java,在执行下面的代码时,设备上“username.txt”文件的大小不断增加。原因是什么 package files2; import java.io.FileNotFoundException; import java.io.File; import java.io.PrintStream; import java.util.Scanner; public class extractor { public static void main(String[] args)throws Fil
package files2;
import java.io.FileNotFoundException;
import java.io.File;
import java.io.PrintStream;
import java.util.Scanner;
public class extractor {
public static void main(String[] args)throws FileNotFoundException {
Scanner fromFile=new Scanner(new File("emails.txt"));
PrintStream toFile=new PrintStream("username.txt");
char symbol;
while(fromFile.hasNext()) {
symbol=fromFile.findWithinHorizon(".",0).charAt(0);
while(symbol !='@') {
toFile.print(symbol);
symbol=fromFile.findWithinHorizon(".",0).charAt(0);
}
fromFile.nextLine();
toFile.println();
}
fromFile.close();
toFile.close();
}
}
原因是您正在写入该文件。你期待什么?原因是因文特·罗普韦尔,你一直在给它写信。如果写入文件,文件数量会增加,这很正常。@VidorVistrom(fromFile.hasNext())在到达文件末尾后不会返回flase?
findWithinHorizon(“.”,0)
将查找任何字符-如果要查找点,需要将其转义:findWithinHorizon(\\”,0)。