bufferedreader

readLine() loop not exiting until remote client closes connection

不想你离开。 提交于 2019-12-29 08:26:26
问题 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 =

Maximum line length for BufferedReader.readLine() in Java?

孤者浪人 提交于 2019-12-28 12:14:34
问题 I use BufferedReader's readLine() method to read lines of text from a socket. There is no obvious way to limit the length of the line read. I am worried that the source of the data can (maliciously or by mistake) write a lot of data without any line feed character, and this will cause BufferedReader to allocate an unbounded amount of memory. Is there a way to avoid that? Or do I have to implement a bounded version of readLine() myself? 回答1: The simplest way to do this will be to implement

BufferedReader is skipping every other line when reading my file in java

空扰寡人 提交于 2019-12-28 04:33:04
问题 So Im working of reading a file containing appointments that I wrote to earlier in my code. I want to sift through the text file and find appointments on a certain date and add them to an ArrayList but when the BufferedReader goes through it, it skips ever other line... Heres my code public ArrayList<String> read(int checkDay, int checkMonth, int checkYear) { ArrayList<String> events = new ArrayList<String>(); BufferedReader in = null; String read; try { in = new BufferedReader(new FileReader

How to convert multi-line text to image using Java [closed]

余生颓废 提交于 2019-12-26 16:05:23
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . I want to ask one question regarding my code which is how do I convert a multiple-line text into a single image using BufferReader. I am able to get the image of the text but all the lines of the text are coming as one single string in one line. Enclosing my code. Please review my code and suggest

How to convert multi-line text to image using Java [closed]

这一生的挚爱 提交于 2019-12-26 16:03:10
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . I want to ask one question regarding my code which is how do I convert a multiple-line text into a single image using BufferReader. I am able to get the image of the text but all the lines of the text are coming as one single string in one line. Enclosing my code. Please review my code and suggest

Confused on how to use BufferedReader for reading arraylist of User objects

ⅰ亾dé卋堺 提交于 2019-12-25 17:46:12
问题 After the user is registered, they can login which is supposed to read their details from a text file by using a BufferedReader. However, I am unsure of how to use a BufferedReader to read the arraylist of User objects line by line to check the details are in the text file and allow for the user to login. This is what I have written: public class LoginJFrame extends javax.swing.JFrame { ArrayList<User> users = new ArrayList<>(); public LoginJFrame() { initComponents(); } private void

AWS Lambda - Buffered reader

寵の児 提交于 2019-12-25 06:32:39
问题 I am using Java on AWS Lambda to get the URL source code of the site. I have the following code: URL yahoo = new URL(url); URLConnection yc = yahoo.openConnection(); yc.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); BufferedReader in = new BufferedReader(newInputStreamReader(yc.getInputStream(), "UTF-8")); String inputLine; StringBuilder a = new StringBuilder(); while ((inputLine = in.readLine()) != null)a.append(inputLine); in.close(); System.out

AWS Lambda - Buffered reader

…衆ロ難τιáo~ 提交于 2019-12-25 06:30:03
问题 I am using Java on AWS Lambda to get the URL source code of the site. I have the following code: URL yahoo = new URL(url); URLConnection yc = yahoo.openConnection(); yc.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); BufferedReader in = new BufferedReader(newInputStreamReader(yc.getInputStream(), "UTF-8")); String inputLine; StringBuilder a = new StringBuilder(); while ((inputLine = in.readLine()) != null)a.append(inputLine); in.close(); System.out

Distributed jar file not picking up my .txt file

Deadly 提交于 2019-12-25 04:55:27
问题 I'm using OS X, Netbeans 7.3 Beta 2, Java. I have a program which reads from a text file. When running my distributed jar, my program does not utilise this .txt file. Here are my two packages - ignore all java files in com.john.view apart from SPPMainGUI2.java: As you can see, cpass.txt is found in com.john.spp. Here is how I use it: BufferedReader in = null; try { in = new BufferedReader(new FileReader("cpass.txt")); } catch (FileNotFoundException ex) { Logger.getLogger(SPPMainGUI2.class

Make FileReader read every fourth line with a loop

☆樱花仙子☆ 提交于 2019-12-25 02:31:49
问题 My problems is that I have to arrange, when searching for a customer, arrange the while loop to only examine every fourth line read. This is the code I already have on this problem: BufferedReader br = new BufferedReader(new FileReader("Customers.txt")); String line; while ((line = br.readLine()) != null) { ... } br.close(); Does anybody know what needs to be at the place of "..."? Thanks! 回答1: Just call br.readLine() 3 times at the end of the loop, discarding the output: BufferedReader br =