bufferedreader

Buffered Reader HTTP POST

断了今生、忘了曾经 提交于 2019-11-30 23:57:24
Looking for a bit of help, I have currently written a HTTP server. It currently handles GET requests fine. However, whilst using POST the buffered reader seems to hang. When the request is stopped the rest of the input stream is read via the buffered reader. I have found a few things on google. I have tried changing the CRLF and the protocol version from 1.1 to 1.0 (browsers automatically make requests as 1.1) Any ideas or help would be appreciated. Thanks I agree with Hans that you should use a standard and well-tested library to do this. However, if you are writing a server to learn about

How to know if a BufferedReader Stream is closed

牧云@^-^@ 提交于 2019-11-30 22:36:53
问题 I have two threads in Java. First thread is closing a bufferedreader ( br.close() ) When the second thread does a read on the same reader I get an IOException (Stream Closed) I get this exception even if I use br.ready() Is there a way to know if the stream is already closed? 回答1: The method ready() will throw an exception if closed. But even if you added a closed check method, so long as the lock is released between calls (which it is for BufferedReader ), the reader might be closed by the

Why do i get a NullPointerException at If statement in do while loop when reading a simple textfile in Java

百般思念 提交于 2019-11-30 21:41:14
问题 I'm new in Java, I have a lot of work with text and I've got an idea to make a simple program to do my work. I'm getting error Exception in thread "main" java.lang.NullPointerException at com.text.work.Main.main(Main.java:25) public class Main { public static void main(String[] args) throws IOException { int someNumber = 0; PrintWriter saveFileOne = new PrintWriter("save.txt"); PrintWriter saveFileTwo = new PrintWriter("otherThings.txt"); FileReader fileReader = new FileReader("read.txt");

BufferedReader, detecting if there is text left to read

爷,独闯天下 提交于 2019-11-30 21:40:18
I'm running a thread and everytime it runs, It should be checking to see if there is a new line to read from the BufferedReader although, it gets stuck waiting for a line to exist, thus halting the entire code. if((inputLine = bufferedReader.readLine()) != null){ System.out.println(inputLine); JOptionPane.showMessageDialog(null, inputLine); } Is there a way to better check if there is text in a BufferedReader to be read? No, there's no easy way to do that. BufferedReader has a ready call, but that only applies to the read calls, not the readLine call. If you really want a readLine that's

how to read last line in a text file using java [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-11-30 20:25:21
This question already has an answer here: Quickly read the last line of a text file? 9 answers I am making a log and I want to read the last line of the log.txt file, but I'm having trouble getting the BufferedReader to stop once the last line is read. Here's my code: try { String sCurrentLine; br = new BufferedReader(new FileReader("C:\\testing.txt")); while ((sCurrentLine = br.readLine()) != null) { System.out.println(sCurrentLine); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (br != null)br.close(); } catch (IOException ex) { ex.printStackTrace(); } } Steve P. Here

How do I close a file after catching an IOException in java?

拟墨画扇 提交于 2019-11-30 19:41:00
All, I am trying to ensure that a file I have open with BufferedReader is closed when I catch an IOException, but it appears as if my BufferedReader object is out of scope in the catch block. public static ArrayList readFiletoArrayList(String fileName, ArrayList fileArrayList) { fileArrayList.removeAll(fileArrayList); try { //open the file for reading BufferedReader fileIn = new BufferedReader(new FileReader(fileName)); // add line by line to array list, until end of file is reached // when buffered reader returns null (todo). while(true){ fileArrayList.add(fileIn.readLine()); } }catch

Buffered Reader HTTP POST

时间秒杀一切 提交于 2019-11-30 18:49:48
问题 Looking for a bit of help, I have currently written a HTTP server. It currently handles GET requests fine. However, whilst using POST the buffered reader seems to hang. When the request is stopped the rest of the input stream is read via the buffered reader. I have found a few things on google. I have tried changing the CRLF and the protocol version from 1.1 to 1.0 (browsers automatically make requests as 1.1) Any ideas or help would be appreciated. Thanks 回答1: I agree with Hans that you

BufferedReader default buffer size?

南笙酒味 提交于 2019-11-30 15:06:01
问题 According to the documentation, BufferedReader(Reader) uses a default buffer size, while the second constructor, BufferedReader(Reader, int) allows the buffer size to be set. public BufferedReader(Reader in) Creates a buffering character-input stream that uses a default-sized input buffer. However, the docs do not not mention what the default buffer size is. What is the default buffer size of a BufferedReader? 回答1: The default buffer size is 8192 characters http://developer.android.com

Can I peek on a BufferedReader?

夙愿已清 提交于 2019-11-30 14:44:48
问题 Is there a way to check if in BufferedReader object is something to read? Something like C++ cin.peek() . Thanks. 回答1: You can try the "boolean ready()" method. From the Java 6 API doc: "A buffered character stream is ready if the buffer is not empty, or if the underlying character stream is ready." BufferedReader r = new BufferedReader(reader); if(r.ready()) { r.read(); } 回答2: You can use a PushbackReader. Using that you can read a character, then unread it. This essentially allows you to

BufferedReader directly to byte[]

╄→尐↘猪︶ㄣ 提交于 2019-11-30 13:53:34
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-1"); int i=0; for (int counter = 0; counter < message.length(); counter++) { i++; System.out.println