learning java input output: tutorials for a confused student sought!
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
learning java input output: tutorials for a confused student sought!
Background:
I'm getting back into university next year, so I'm working on a simple java program now, to freshen up my brain. (java being the language of the school.)*
Specifics:
The aspect I'm looking at right now is java input/output, specifically reading and writing a text file.
My problem is I can't understand the tutorials for I/O that I'm finding on google- this includes the Sun tutorials.
Please, can someone give me a good, easy to understand I/O tutorial, that is current and not depreciated (Java 5 or 6.)
I want to know:
How best to read a (multi line) file.
How best to write to a file.
How to add (write) to a file, leaving the old contents intact.
I learn from clearly commented code best. (with a little blurb explaining what that code is meant to do.)
[edit] Oh, and keep it simple. I don't want to deal with complex stuff that I don't need to know about yet. [/edit]
I'm not interested in buying books. Websites, please.
Thank you very much for your answers.
-titanium_geek
* I know java is a flawed language, but it's what I am required to work with, so please don't recommend I, learn C instead, for example.
Last edited by titanium_geek; 12-09-2008 at 02:06 AM.
Reason: clarification, added details
Background:
I'm getting back into university next year, so I'm working on a simple java program now, to freshen up my brain. (java being the language of the school.)*
Specifics:
The aspect I'm looking at right now is java input/output, specifically reading and writing a text file.
My problem is I can't understand the tutorials for I/O that I'm finding on google- this includes the Sun tutorials.
Please, can someone give me a good, easy to understand I/O tutorial, that is current and not depreciated (Java 5 or 6.)
I want to know:
How best to read a (multi line) file.
How best to write to a file.
How to add (write) to a file, leaving the old contents intact.
I learn from clearly commented code best. (with a little blurb explaining what that code is meant to do.)
[edit] Oh, and keep it simple. I don't want to deal with complex stuff that I don't need to know about yet. [/edit]
I'm not interested in buying books. Websites, please.
Thank you very much for your answers.
-titanium_geek
* I know java is a flawed language, but it's what I am required to work with, so please don't recommend I, learn C instead, for example.
First a disclaimer - I am not a Java guy.
Still, I think your post shows not confusion, but rather laziness. Or my mood is just bad ...
Anyway, the points are:
in Java everything is in classes;
classes have names and methods;
you just need first to identify the classes which deal with IO;
you then perform web search for the classes and their methods, there is a lot of Java code around, there is Google code search, so in the end you will find code, hopefully with comments
In Russian they are saying "(you not only want food), you also want it to be served on a beautiful plate" - an approximate translation - that's what I more or less felt reading your post.
And to get the knowledge you'll have to write code yourself, making mistakes and fixing them, asking yourself questions and figuring out answers - this is what learning about.
You, of course, can/may ask questions, but they should be specific, i.e., for example, you quote a manual page and point to the pieces which is not clear to you, and explain in detail what exactly is not clear, giving your possible interpretations and asking for clarifications.
Too bad you are not interested in getting a book. I would strongly recommend E.R. Harold's "Java I/O" (O'Reilly), which is one of the best Java books I have ever read (from simple I/O to encryption, archiving, programming for hardware etc). It is all-inclusive, has lots of comments and extensive in-depth explanation, full source code illustrating everything, etc. Sure, you can figure it all out in bits and pieces and never gain an understanding of the fundamentals - but the book will serve these all up in a well-organized way in just 700 pages.
I completely sympathize with you. I've never understood from Java 1.0 why they never gave you a simple "printf" (or better, a FORTRAN or COBOL-style "write").
I completely sympathize with you. I've never understood from Java 1.0 why they never gave you a simple "printf" (or better, a FORTRAN or COBOL-style "write").
OK: what I would like, is for someone to tell me what java (5 or 6) classes are used for input/output. Then I can read up about them and work out how to use them.
I'm trying to be vague because in the past, I've asked questions with specific information about the program I was trying to write, and someone wrote the whole program for me, which isn't quite helpful when I'm trying to learn how to do it myself.
Start by inspecting the InputStream and OutputStream classes. They are unusable as they are abstract but they are the basis of nearly all other byte stream classes, i.e. their methods are shared by all those classes. The same goes for the Reader and Writer classes, which are the basis of nearly all character streams.
The truth is that I/O is extremely easy - once you get the fundamentals right (just a handful of methods and principles), you can work out the rest from there.
I completely agree with arunmathew1984's recommendation for Bruce Eckel's classic "Thinking in Java". My Third Edition copy is well-worn and dog-eared, the current Fourth Edition covers Java 6. It's a great primer for the novice; it's a great reference for the practitioner.
And I apologize for Sergei's completely unwarranted reponse to your original question. You've been around LQ long enough to know that's not the norm, but I'm sorry that it happened.
IMHO .. PSM
PS:
Bruce Eckel's home page ... and the free download of his 3rd Edition (which I can personally assure you is still an excellent, useful reference) is here: http://mindview.net/
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.