Read and Write Files - java.io

Hey folks! I'm back with another simple how-to-do tip. This time I'm going to talk about very common library in Java SE. That is java.io package. When you coding your Java application, there are some situation you might need to read or write a file from/into the local disk. Believe me or not, everytime I need it, I always ended up with googling it :D So I thought it will be really useful if I can do a simple example and publish it in the blog.

Okay, what I'm going to do today is write an app to read text files from the local disk and write it back to the disk with modified changes. Destination file may be the same source file or a new text file. Lets get our hands dirty.

File reading

File writing
File filter
This will filter the text files(.txt) from your local disk and ignore other file types.
Final app

Note: I have removed all the exception handling codes for more clarity. So make sure you handle I/O exceptions appropriately. I haven't talked much about GUI codes here as well and I assume that you already familiar with Java Swing stuff. You can get the full source code from my git repo.

Git url: https://github.com/arlahiru/JavaIODemoApp

That's it folks! Don't forget to give me your feedback and please let me know if there are any mistakes. See you soon. Byee!