IO: ClassicIoBuffered
Buffered to some degree
This commit is contained in:
49
ClassicIoBuffered/src/ClassicIoBuffered.java
Normal file
49
ClassicIoBuffered/src/ClassicIoBuffered.java
Normal file
@@ -0,0 +1,49 @@
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author KAJE
|
||||
*
|
||||
*/
|
||||
public class ClassicIoBuffered {
|
||||
|
||||
public static int lineCount(String path){
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
fis = new FileInputStream(path);
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
BufferedInputStream bis = new BufferedInputStream(fis);
|
||||
int cnt = 0;
|
||||
int b;
|
||||
try {
|
||||
while ((b = bis.read()) != -1) {
|
||||
if (b == '\n') cnt++;
|
||||
}
|
||||
bis.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args){
|
||||
long startTime = System.nanoTime();
|
||||
System.out.println("Lines: " + String.valueOf(lineCount("input.txt")));
|
||||
long stopTime = System.nanoTime();
|
||||
System.out.println("Time it took: " + (stopTime - startTime));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user