-
->Re: Java I/O
"Bob" <ups2000@hotmail.com> wrote:
>
>MAy be somebody knows where I can find examples how to read from FIle in
Java
>Thanks
Bob,
I'd strongly advise you take a look at 'Beginning Java 2' by Ivor Horton,
Pub.: Wrox 1999, ISBN: 1-861002-23-8. I found it a great book for learning
Java, streets ahead of any 'learn it in 21 days' books. This covers first
file output and streams, then stream input (from any source -files in particular).
The style is good and the material is uncomplicated but clear.
Once you've covered the basics you'll need a good reference that'll cover
the interesting wrinkles (& wot you forgot!). For that I bought 'Java In
a Nutshell' by David Flannagan, Pub.: O'Reilly, ISBN1-56592-487-8.
But here's a snippet to get you started, reading in a series of numbers:
String directory = "C:/temp";
String fName = "junk.txt";
//define a file:
File myFile = new File(directory, fName);
DataInputStream numsIn = new DataInputStream(
new FileInputStream(myFile));
int num = 0;
boolean EOF = false;
while (!EOF) {
try {
processNumbers(numsIn.readInt); //-or whatever...
}
catch (EOFException e) {
EOF = true; // terminates your read loop.
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks