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

Whoever 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 doesn’t even require any sign-in, The good thing is that it can accept your lovely nick name also and the URL is not mandatory too.
Thanks for your patience
~Krishna(I love "Transparency")

Popular Posts

Enter your email address:

Buffs ...

Tags


Powered by WidgetsForFree