File operations in Java Read file, write into file, Append file

File operations in Java Read file, write into file, Append file

File operations involved majorly are reading it , writing into a file and appending it.
Reading from a File : 

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


Writing into a File : 


try {
    BufferedWriter out = new BufferedWriter(new FileWriter("outfilename"));
    out.write("aString");
    out.close();
} catch (IOException e) {
}


Appending to a File : 

try {
    BufferedWriter out = new BufferedWriter(new FileWriter("filename", true));
    out.write("aString");
    out.close();
} catch (IOException e) {
}


2 comments to "File operations in Java Read file, write into file, Append file"

  • This is very interesting, You are a very skilled blogger.
    I've joined your rss feed and look forward to seeking more of your wonderful post. Also, I have shared your web site in my social networks!
    My website ; Privacy Defender

  • Sweet blog! I found it while surfing around on Yahoo News.
    Do you have any suggestions on how to get listed in Yahoo News?
    I've been trying for a while but I never seem to get there! Thanks
    My site : ameri loan

Post a Comment

Who ever writes Inappropriate/Vulgar comments to context, generally want to be anonymous …So I hope U r not the one like that?
For lazy logs u can at least use Name/URL option which don’t even require any sign-in, good thing is that it can accept your lovely nick name also and URL is not mandatory too.
Thanks for your patience
~Krishna(I love "Transparency")
వీలయితే నాల్గు పోస్టులు ...కుదురితే ఒక కామెంటూ ...

Translate

Enter your email address:

Buffs ...

Visitors


hits counter
View My StatsCheck Google Page Rank

Add to Google Reader or Homepage

Bookmark and Share

Tags


Powered by WidgetsForFree