bufferedreader

Read and Write Text in ANSI format

元气小坏坏 提交于 2020-01-09 04:39:05
问题 Please have a look at the following code import java.io.*; public class CSVConverter { private File csvFile; private BufferedReader reader; private StringBuffer strBuffer; private BufferedWriter writer; int startNumber = 0; private String strString[]; public CSVConverter(String location, int startNumber) { csvFile = new File(location); strBuffer = new StringBuffer(""); this.startNumber = startNumber; //Read try { reader = new BufferedReader(new FileReader(csvFile)); String line = ""; while(

How do I track reading of a a file using .readLine() in java?

旧巷老猫 提交于 2020-01-07 04:54:50
问题 I am reading a file using bufferedREader ,the file is a text file with lot of text here is how I am reading it while(true) //I know the loop is not perfect just ignore it for now, i wanna concentrate on the tracking { try { br.readLine(); } catch(IOException e) { break; } catch (Exception e) { break; } } I want to track what percentage of the file I have read so I can use that percentage value in my progress bar like this: while(true) { try { br.readLine(); progressBar.setValue(percentageRead

Reading Lines and byte[] from input stream

放肆的年华 提交于 2020-01-07 03:04:49
问题 I have a network socket which recieves the following types of messages: (about 24 per second) Commands EG: [Pos,1,2,3,4,1,2,3,4]\n Images: [IMG,36000]\nbyte[36000] (byte[36000] is an array of 36000 bytes) So I would need an Reader for that stream that is able to read lines and byte[]. The problem is, that the BufferedReader converts the charset, which is very, very, very bad for images, so reading a string and converting it to byte seems not to be an option. I tried to connect a

Calculating Average/Max/Min from an array in Java

旧城冷巷雨未停 提交于 2020-01-06 08:32:08
问题 I have my code that will read in a a list of numbers in a file called "QuizScores.txt". However, in this file, certain numbers contain letters. I have told my program to simply ignore those instances and move onto the next number. My issue now if that my code is only reading one line at a time where I need it to look at the entire file, read it in, calculate the average, the maximum, and the minimum, and finally output that to a file called "QuizStats.txt". Any help with this would be greatly

Calculating Average/Max/Min from an array in Java

青春壹個敷衍的年華 提交于 2020-01-06 08:31:10
问题 I have my code that will read in a a list of numbers in a file called "QuizScores.txt". However, in this file, certain numbers contain letters. I have told my program to simply ignore those instances and move onto the next number. My issue now if that my code is only reading one line at a time where I need it to look at the entire file, read it in, calculate the average, the maximum, and the minimum, and finally output that to a file called "QuizStats.txt". Any help with this would be greatly

Using inputStream and OutputStream to read and write data to a process

泄露秘密 提交于 2020-01-05 23:45:08
问题 I am currently running a .class file as a process. The .class file is a simple program that asks the user to input a number, takes the input and prints the user's input back to the screen. Up to now, i have managed to print the "Enter a number: " statement from the process on the console through InputStream and write the input entered by the user through OutputStream . I am unable to print the last statements on the screen, which should be "You entered : " + userinput My code is: String

Java BufferedReader reading form socket doesn't return null

↘锁芯ラ 提交于 2020-01-05 07:58:28
问题 I'm currently writing an app in Java that opens a socket and should receive and send data over it. It is my understanding that BufferedReader.readLine() returns null once the buffer is empty. However, my code doesn't exit from the loop that reads the lines from the BufferedReader. The idea is thata i receive a list of songs and then send a value to the server where a song starts playing. This is the code: package me.frankvanbever.MediaServerClient; import java.io.BufferedReader; import java

Reading java file with escape characters for newline

十年热恋 提交于 2020-01-04 01:29:53
问题 I have a Unicode file that needs to be exported to database(Vertica). The column delimiter is CTRL+B, record delimiter is newline(\n). Whenever there is a newline within a column value, CTRL+A is used as escape character. When I use BufferedReader.readLine() to read this file, the records with ID's 2 and 4, are read as two records. Whereas I want to read them as a single whole record as given in output. Here is the example input file. | stands for CTRL+B and ^ stands for CTRL+A. Input ID|Name

Java 8 BufferedReader lines() method prints different count number

被刻印的时光 ゝ 提交于 2020-01-03 08:28:12
问题 I have faced a problem to count line number using lines() method of BufferedReader . Following is the content of test.txt file. 1 Career 2 Filmography 3 Awards 4 References 5 External Here is the source code to count line number twice. BufferedReader br=new BufferedReader(new FileReader(new File("test.txt"))); long lineNo=br.lines().count(); long lineNo2=br.lines().count(); System.out.println(lineNo); // 5 System.out.println(lineNo2);// 0 Here, I have question why second line of lineNo2 print

How to read word by word from file?

喜你入骨 提交于 2020-01-03 05:33:32
问题 Could anybody post here some code how can I read word by word from file? I only know how to read line by line from file using BufferedReader. I'd like if anybody posted it with BufferedReader. I solved it with this code: StringBuilder word = new StringBuilder(); int i=0; Scanner input = new Scanner(new InputStreamReader(a.getInputStream())); while(input.hasNext()) { i++; if(i==prefNamePosition){ word.append(prefName); word.append(" "); input.next(); } else{ word.append(input.hasNext()); word