Reading a File with a Progress Monitor in Java
Submitted by donbermoy on Thursday, December 11, 2014 - 11:18.
This tutorial will teach you how to create a program that can read files but with a progress monitor that loads first the file and then read it.
So, now let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of progressMonitorInputStream.java.
2. Import the following package library:
3. We will have first to have a try and catch method. In the try method, initialize the following variables:
Next, to access the content of the file, we will use the while loop and have the contents of the file be put into the line variable. Then close the file with your br variable.
4. In your catch method, get the following message when you have an error. Then provide an exit for your program if there is an error.
Output:
Here's the full code of this tutorial:
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware
- import java.io.*; // used to access FileInputStream, InputStreamReader, and BufferedReader class
- import javax.swing.*; // used to access ProgressMonitorInputStream clas
- try {
- FileInputStream fis = new FileInputStream("READ FIRST.txt"); // access your file in the file input stream
- ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(null, "Reading the file..", fis); // this will load and monitor the progress of the file
- InputStreamReader isr = new InputStreamReader(pmis); //used to access the progress monitor when reading the file
- while ((line = br.readLine()) != null) {
- }
- br.close();
- }
- import java.io.*; // used to access FileInputStream, InputStreamReader, and BufferedReader class
- import javax.swing.*; // used to access ProgressMonitorInputStream clas
- public class progressMonitorInputStream {
- try {
- FileInputStream fis = new FileInputStream("READ FIRST.txt"); // access your file in the file input stream
- ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(null, "Reading the file..", fis); // this will load and monitor the progress of the file
- InputStreamReader isr = new InputStreamReader(pmis); //used to access the progress monitor when reading the file
- while ((line = br.readLine()) != null) {
- }
- br.close();
- }
- }
- }
Add new comment
- 167 views