Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I/O stream not working right

 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The variables x, y, width, height, and adds all are a part in another part of my code, for graphics. Since they are attached to these variables, if something goes wrong, the items do not show up. That part I know for sure is working right. I removed this code and it showed just fine. Anyway here is the output (with no file in the directory):

file1.txt content:

My problem code is below. Here is the begging of my code showing initialization of variables...



I've never completely understood File inputs and outputs (I used to program with Autohotkey), so I'm probably doing everything wrong. Please help me fix this crap I call code.
Thanks,
cc11rocks aka John Price
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
john price wrote:

1) never use == for String comparison. Always use .equals().
2) br.readLine() will read the next line each time it's called. I don't think you want that, but to use the currently read line instead.
3) In that case, the loop already guaranteed that the result is not null, so the second part can be skipped.

The new start of your loop:

One more possible improvement: use a switch instead of the "if check == 0 else if check == 1 ..." part.
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much. It works 100% now!
,
John Price, aka cc11rocks
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic