Ich versuche, die Datei "ab.txt" zu lesen und speichern Sie ihren Inhalt in "Output.txt" K-mal, so dass ich nehme, den Inhalt der Eingabedatei K mal in der Ausgabe erhalten Datei, aber ich bekomme nur einmal, während es auf Konsole Kth Zeiten druckt.Ausgabe nicht als intent
import java.io.*;
import java.util.Scanner;
class PrintStreamTest1
{
public static void main(String... l)throws IOException
{
int k=0;
long avgTime=0;
while(k<100)
{
long startTime=System.nanoTime();
String s;
Scanner fin=new Scanner(new BufferedInputStream(new FileInputStream("ab.txt")));
PrintStream output=new PrintStream("Output.txt");
while(fin.hasNextLine())
{
s=fin.nextLine();
System.out.println(s);
output.print(s+"\n");
}
avgTime=avgTime+((System.nanoTime()-startTime)/10000000);
fin.close();
output.close();
k++;
}
System.out.println("\n "+ avgTime+"ms");
}
}
Es sollte auf Ausgabestrom sein 'PrintStream output = new PrintStream ("Output.txt"); 'nicht inputstream – Sanjeev
@Sanjeev Sie sind richtig. Ich wurde von der Eingabedatei verwirrt. Wird das beheben. Danke – Eran
Keine Probleme .. es passiert :) – Sanjeev