bufferedreader

BufferedReader to skip first line

霸气de小男生 提交于 2019-11-30 03:27:58
I am using the following bufferedreader to read the lines of a file, BufferedReader reader = new BufferedReader(new FileReader(somepath)); while ((line1 = reader.readLine()) != null) { //some code } Now, I want to skip reading the first line of the file and I don't want to use a counter line int lineno to keep a count of the lines. How to do this? You can try this BufferedReader reader = new BufferedReader(new FileReader(somepath)); reader.readLine(); // this will read the first line String line1=null; while ((line1 = reader.readLine()) != null){ //loop will run from 2nd line //some code } Use

BufferedReader directly to byte[]

自作多情 提交于 2019-11-29 19:53:04
问题 is there any possibility my following BufferedReader is able to put the input directly into a byte[]? public static Runnable reader() throws IOException { Log.e("Communication", "reader"); din = new DataInputStream(sock.getInputStream()); brdr = new BufferedReader(new InputStreamReader(din), 300); boolean done = false; while (!done) { try { char[] buffer = new char[200]; int length = brdr.read(buffer, 0, 200); String message = new String(buffer, 0, length); btrar = message.getBytes("ISO-8859

readLine() loop not exiting until remote client closes connection

风格不统一 提交于 2019-11-29 18:09:48
I'm having a problem with a Java SocketServer, i'm building a very basic Java handled Web Server. So i'm creating a socket server, this is the code from the run method as i have made the server threaded. The problem i'm having is that the server code seems to freeze as while((line = reader.readLine()) != null) until the remote client closes the connection. I'm using the chrome plugin ARC (Advanced REST Client) to do the testing with. public void start() throws ServerException{ this.running = true; try{ this.server = new ServerSocket(this.port); }catch(IOException ex){ System.err.println(

Read Input until control+d

一笑奈何 提交于 2019-11-29 18:03:38
I want to prompt the user to begin entering characters and I want them to be able to enter characters as long as they want until they hit control+d to exit. For example, they can type a string of numbers like: 1234567 and as soon as they decide to hit control+d the line that they entered will be displayed (so without having to hit return) I am thinking I'll need a buffered reader or something. Any suggestions? What rlibby said is spot on: the CTL-D will cause the terminal to flush buffered input to the JVM. However, the keypress event itself is captured and acted on by the terminal and not

How to read a text file into jtextarea in Java Swing

橙三吉。 提交于 2019-11-29 15:27:14
Here is my code: try { String textLine; FileReader fr = new FileReader("ad.txt"); BufferedReader reader = new BufferedReader(fr); while((textLine=reader.readLine()) != null) { textLine = reader.readLine(); jTextArea1.read(reader, "jTextArea1"); } } catch (IOException ioe) { System.err.println(ioe); System.exit(1); } And my .txt file contains the following: contig00001 length=586 numreads=4 CGGGAAATTATCcGCGCCTTCACCGCCGCCGGTTCCACCGACGAACGGATACTGCGtGaa ggCCGCGATCCCGTCggaCGGAAAaCGCCcTGGCCCGGGAaCATACCGTTCGGGCCGCCA AGTGTTATAGCCGGACCACTTGTCAGAACATTTCCaaTCCGAAGATGTGAGTtCGGAAGg

Getting the character returned by read() in BufferedReader

佐手、 提交于 2019-11-29 13:24:10
问题 How can I convert an integer returned by the read() in a BufferedReader to the actual character value and then append it to a String? The read() returns the integer that represents the character read. How when I do this, it doesn't append the actual character into the String. Instead, it appends the integer representation itself to the String. int c; String result = ""; while ((c = bufferedReader.read()) != -1) { //Since c is an integer, how can I get the value read by incoming.read() from

How can I read from a BufferedReader in Java without blocking?

左心房为你撑大大i 提交于 2019-11-29 08:04:40
I want to send a command to a server, and find out if I get a response. Right now i am using BufferedReader 's readline() function, which blocks until there's a response from server, but all I want to do is verify that there's a response from the server in the first place. I tried using ready() or reset() to avoid this block, but it doesn't help. This is causing my program to get stuck waiting for the server to respond, which never happens. InputStreamReader seems to do the same thing, by my understanding of things. Other questions I found here on the subject didn't answer my question, so

Java-Convert String to int when using BufferedReader

给你一囗甜甜゛ 提交于 2019-11-29 07:16:48
How do you convert a String to int when using BufferedReader? as far as i remember,its something like below: System.out.println("input a number"); int n=Integer.parseInt(br.readLine(System.in)); but for some reason,its not working. the error message says: no suitable method found for readLine(java.io.InputStream) it also says br.readLine is not applicable An InputStreamReader needs to be specified in the constructor for the BufferedReader . The InputStreamReader turns the byte streams to character streams. As others have mentioned be cognizant of the exceptions that can be thrown from this

Socket closed exception [duplicate]

我们两清 提交于 2019-11-29 06:54:23
This question already has an answer here: Proper way to close an AutoCloseable 1 answer I wrote a simple server and client example as below . Client : Open a connection Get outputstream , write to stream and close the output stream Get inputstream and read from the stream. Getting exception at this point public class DateServer { public static void main(String[] args) throws InterruptedException { ServerSocket serverSocket = null; Socket client = null; try { serverSocket = new ServerSocket(6013); while (true) { client = serverSocket.accept(); OutputStream outputStream = client.getOutputStream(

Difference between BufferedReader and BufferedInputStream

徘徊边缘 提交于 2019-11-29 05:52:39
问题 What are the differences between BufferedReader , BufferedInputStream and Scanner in java? BufferedReader reads the text and BufferedInputStream reads byte . Is there any difference other than this? 回答1: I guess, the difference is the same as between reader and inputstream: one is character-based, another is byte-based. For example, reader normally supports encoding... Edit: Check this question: The difference between InputStream and InputStreamReader when reading multi-byte characters 回答2: