I'm trying to read the file "ab.txt" and saving its content in "Output.txt" Kth times,so i'm suppose to get the content of input file K times in output file,but i'm getting only once whereas it is printing on console Kth times.
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");
}
}