Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
currentTimeMillis();


while (linReader.hasNext())
{
String line = linReader.nextLine();
System.out.println(line);
}
linReader.close();
long estimatedTime = System.currentTimeMillis() - start_time;
System.out.println(estimatedTime);
}
}
}
>

What I have tried:

<
C#
 else{
			 Scanner linReader = new Scanner(inputfile);
			        long start_time = System.currentTimeMillis();


			        while (linReader.hasNext())
			        {
			            String line = linReader.nextLine();
			            System.out.println(line);
			            }
			        linReader.close();
                        long estimatedTime = System.currentTimeMillis() - start_time;
			            System.out.println(estimatedTime);
            }
}
}



I am trying to read file through linebyline method and i want time as output. But my line by line method is not outputting time. Instead of giving time, it is giving me this as output

Enter an input file namek.txt
Enter an output file namei.txt
Enter an mode by pressing 0 and 1
0 -- character-by-character mode
1 -- means line-by-line mode
1
k.txt
0

Which is wrong
Posted
Updated 1-Nov-16 10:50am
v2
Comments
[no name] 28-Oct-16 8:55am    
You could try reposting your homework assignment over and over and over and over until someone just does it for you.

Did not read your source code
here is a sample example:
Java
FileInputStream fstream;
BufferedReader br;
fstream = new FileInputStream(fileName);
br = new BufferedReader(new InputStreamReader(fstream, "UTF-8"));
String line;
while ((line = br.readLine()) != null) {
    System.out.printlne(line);
}
br.close();
 
Share this answer
 
You are creating a Scanner object using the inputfile string, so the Scanner will scan that text. You need to create it using the actual file thus:
Java
Scanner linReader = new Scanner(inputStream);

You need to make more use of the Java Documentation: Scanner (Java Platform SE 7 )[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900