tags:

views:

98

answers:

6

hi all. I have just started learning java after C + +. but so far nothing is clear. especially the work with classes.

tell me please how to open a file for reading or writing? it is desirable to provide the code completely.

Thanks. sorry for bad english.

upd: I started to learn java hour ago, but has not yet written a working program.

Thank you all for your answers!

+5  A: 

Maybe you should read the IO part of the sun java tutorial first.

E.g. Reading, writing and creating Files

seanizer
+1  A: 

May the Apache Commons be your friend. There's a FileUtils class that does the job.

Boris Pavlović
I agree, these are very useful, but IMHO the OP first needs to understand how things work
seanizer
On the contrary, I think it's better to have an instant gratification of having the job done and then if needed dive deeper into the domain.
Boris Pavlović
+1  A: 

Here is a great set of tutorials for learning Java: The Java Tutorials.

For a tutorial on how to do I/O, look at the chapter Basic I/O from those tutorials.

Jesper
+1  A: 

Best u go through java complete reference book.... I give sample program i hope this will help u....

public class Abc {
    public static void main(String[] args) {
        Abc.modemp();
    }
    public static void modemp() {
        String detail;
        try {
            BufferedReader empdtil = new BufferedReader(new FileReader("File Location"));
            while ((detail = empdtil.readLine()) != null) {
                System.out.println(detail);
            }
            empdtil.close();
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
    }
}
Mouli