open close files

hi

I would like to ask how to open , close , wwrite to , read from file in java

thank you
Elyaa
ElyaaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
jokturCommented:
Are you using java standard applications or java applets?
0
 
nutparCommented:
Reading Text from a File

    try {
        BufferedReader in = new BufferedReader(new FileReader("infilename"));
        String str;
        while ((str = in.readLine()) != null) {
          System.out.println(str);
        }
        in.close();
    } catch (IOException e) {
    }

Writing to a File

If the file does not already exist, it is automatically created.
    try {
        BufferedWriter out = new BufferedWriter(new FileWriter("outfilename"));
        out.write("aString");
        out.close();
    } catch (IOException e) {
    }

0
 
CleanupPingCommented:
Elyaa:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
girionisCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points to CEHJ

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer
0
All Courses

From novice to tech pro — start learning today.