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.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.)*
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.)
 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.
* 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.
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
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/