• Post Reply Bookmark Topic Watch Topic
  • New Topic

Read from file  RSS feed

 
mike statham
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code but need to read from a file

 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And your question is....?
 
Mark Beardsley
Ranch Hand
Posts: 32
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lets take a stab at this one. I am assuming - NEVER a safe thing to do - that you are asking how to read from a file. Well Java has the concept of a stream and a stream is used to connect a source of data with a destination or a user of that data. Take a look here - http://docs.oracle.com/javase/tutorial/essential/io/ - for a pretty comprehensive primer.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you get rid of the Format object and use the printf method of System.out (a PrintStream) instead. You can find full details in the Formatter class and two descriptions which you can actually understand in the Java™ Tutorials: 1 2.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mike statham wrote:I have the following code but need to read from a file

mike,

Please DontWriteLongLines.

It makes your thread very hard to read, and it's actually bad coding practice (and one I've noticed you're guilty of in quite a lot of your posts).

I've broken yours up this time, but for future reference, please remember:
80 characters max.
(the SSCCE page actually recommends 62)
And that includes string literals AND comments AND long method calls.

Thanks.

Winston
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mike statham wrote:I have the following code but need to read from a file

you should be able to do it with the code you have, providing that your file data corresponds exactly with what your Scanner reads are requesting. In theory you also don't need the System.out.print... calls when you're reading from a file, but they don't do any specific harm.

Winston
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the print calls are useful for debugging. You can remove them (or comment them out) later.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!