• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

I/O stream not working right

 
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much. It works 100% now!
,
John Price, aka cc11rocks
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
Yes, of course, and I accept that blame. In fact, i covet that blame. As does this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic