bufferedreader

Read and Write CSV File using Java

落爺英雄遲暮 提交于 2021-02-20 05:14:33
问题 I have a CSV log file and it contains many rows like this: 2016-06-21 12:00:00,000 : helloworld: header1=2;header2=6;header=0 I want to write them to a new CSV file. public void readLogFile() throws Exception { String currentLine = ""; String nextLine = ""; BufferedReader reader = new BufferedReader(new FileReader(file(false))); while ((currentLine = reader.readLine()) != null) { if (currentLine.contains("2016") == true) { nextLine = reader.readLine(); if (nextLine.contains("helloworld") ==

Read and Write CSV File using Java

大城市里の小女人 提交于 2021-02-20 05:13:15
问题 I have a CSV log file and it contains many rows like this: 2016-06-21 12:00:00,000 : helloworld: header1=2;header2=6;header=0 I want to write them to a new CSV file. public void readLogFile() throws Exception { String currentLine = ""; String nextLine = ""; BufferedReader reader = new BufferedReader(new FileReader(file(false))); while ((currentLine = reader.readLine()) != null) { if (currentLine.contains("2016") == true) { nextLine = reader.readLine(); if (nextLine.contains("helloworld") ==

Read and Write CSV File using Java

ε祈祈猫儿з 提交于 2021-02-20 05:11:40
问题 I have a CSV log file and it contains many rows like this: 2016-06-21 12:00:00,000 : helloworld: header1=2;header2=6;header=0 I want to write them to a new CSV file. public void readLogFile() throws Exception { String currentLine = ""; String nextLine = ""; BufferedReader reader = new BufferedReader(new FileReader(file(false))); while ((currentLine = reader.readLine()) != null) { if (currentLine.contains("2016") == true) { nextLine = reader.readLine(); if (nextLine.contains("helloworld") ==

Read and Write CSV File using Java

主宰稳场 提交于 2021-02-20 05:08:59
问题 I have a CSV log file and it contains many rows like this: 2016-06-21 12:00:00,000 : helloworld: header1=2;header2=6;header=0 I want to write them to a new CSV file. public void readLogFile() throws Exception { String currentLine = ""; String nextLine = ""; BufferedReader reader = new BufferedReader(new FileReader(file(false))); while ((currentLine = reader.readLine()) != null) { if (currentLine.contains("2016") == true) { nextLine = reader.readLine(); if (nextLine.contains("helloworld") ==

Getting java.lang.NumberFormatException in the code

老子叫甜甜 提交于 2021-02-05 06:50:23
问题 Code : I have TriangleSummer class which has class variable static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); My main function is public static void main(String args[]) throws IOException { int noOfTestCases = Integer.parseInt(reader.readLine()); for(int i=0;i<noOfTestCases;i++){ int noOfEntries = Integer.parseInt(reader.readLine()); System.out.println(computeMaxSum(noOfEntries)); } } Relevant part of my computeMaxSum() method is public static int

Why is BufferedReader read() much slower than readLine()?

只愿长相守 提交于 2020-12-24 07:59:00
问题 I need to read a file one character at a time and I'm using the read() method from BufferedReader . * I found that read() is about 10x slower than readLine() . Is this expected? Or am I doing something wrong? Here's a benchmark with Java 7. The input test file has about 5 million lines and 254 million characters (~242 MB) **: The read() method takes about 7000 ms to read all the characters: @Test public void testRead() throws IOException, UnindexableFastaFileException{ BufferedReader fa= new

Why is BufferedReader read() much slower than readLine()?

妖精的绣舞 提交于 2020-12-24 07:57:05
问题 I need to read a file one character at a time and I'm using the read() method from BufferedReader . * I found that read() is about 10x slower than readLine() . Is this expected? Or am I doing something wrong? Here's a benchmark with Java 7. The input test file has about 5 million lines and 254 million characters (~242 MB) **: The read() method takes about 7000 ms to read all the characters: @Test public void testRead() throws IOException, UnindexableFastaFileException{ BufferedReader fa= new