以下のコードを実行すると、デバイス上の "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 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();
}
}
その理由は、そのファイルに書き込んでいるためです。あなたは何を期待していますか? –
理由は何もないループ –
です。ファイルに書き込むとファイルが増えますが、それはかなり正常です。 – magicleon