0

[original text][1]

[results when i print out within Server Class][2]

In my Server Class I want to read each line of the text file, including empty lines but it starts in the middle of the file. I believe it has to do with the ecplise max output. I know because I get the correct output of bytes from each line.

Nameishi
  • 185
  • 1
  • 14
  • 2
    Your code only reads a single line. You should use a loop and iterate over the file. – Tim Biegeleisen Oct 06 '16 at 01:15
  • Nonsense. It reads everything in the file, and stops at EOF. It works for everybody else. NB The only thing you're sending here is the line length, not the line itself. Are you ever closing or flushing `pr`? – user207421 Oct 06 '16 at 01:34
  • Then you should look it up. `pr.flush()`, before you do the next read from the socket. – user207421 Oct 06 '16 at 01:45
  • Now you're claiming it begins from the middle of the file, which not only is impossible but contradicts your original claim. – user207421 Oct 06 '16 at 01:56
  • @EJP i will upload the results, why would i make this up ? – Nameishi Oct 06 '16 at 01:57
  • When are you going to make up your mind what the symptoms are? When are you going to implement the flush I suggested? – user207421 Oct 06 '16 at 01:58
  • i did and there was no difference – Nameishi Oct 06 '16 at 01:59
  • Not shown above, so impossible to comment, except that in the code above it should be after the read loop. In fact the code above doesn't send anything anywhere except to `System.out`, so it's all pretty pointless. Maybe the client code has bugs too: who could possibly know from this evidence? – user207421 Oct 06 '16 at 02:01
  • @EJP i just uploaded two images in the above code one is the original text and the second is my results – Nameishi Oct 06 '16 at 02:04
  • So this isn't the real code. Recompile, rebulld, retest. Or there is more text further up in the console window. – user207421 Oct 06 '16 at 02:06
  • @EJP it was a simple eclipse max output setting, next time don't assume it is just code..because the code was not the issue. – Nameishi Nov 04 '16 at 14:25

2 Answers2

5

Use a loop and iterate over the entire file:

while ((line = buffer.readLine()) != null)) {
    pr.println(line);
}
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • 1
    @Nameish That can only mean that there was only one line in file, or you're not running the code you think you're running. – user207421 Oct 06 '16 at 01:26
  • @Nameishi There's only one line there. QED. An HTML renderer would *render* it as several lines, but that's not what you asked, or what `BufferedReader` is for. Or a server. – user207421 Oct 06 '16 at 01:31
  • It stops at EOF and not before. – user207421 Oct 06 '16 at 01:35
3

You need some kind of loop to iterate through the BufferedReader. If readLine() returns null, you're at the end of the stream and you can break out of the loop.

See API for BufferedReader.

Zhe
  • 396
  • 1
  • 13
  • @Nameishi As you've accepted this answer, you should delete all your comments claiming it doesn't work, and/or explain what was preventing it working *for you.* Was it just a recompile? Or not posting the real code? – user207421 Oct 06 '16 at 03:29
  • I changed the settings on ecplise, that was the issue. Now I see the entire output. my code I provided works fine. – Nameishi Nov 04 '16 at 14:21