File Reading from the specified location
Hi All,
i am new to java, have one requirement.
I need to process the file ---For Ex. input file is having 1000 records . i need to process the first 100 records after that in the second iteration 101-200,third iteration,201-300.......like this i need to process all the records.
can anyone help me?
Re: File Reading from the specified location
Hello and welcome,
What exactly is your problem, is it opening the file and reading the data or the actual iteration code?
// Json
Re: File Reading from the specified location
Hello rajesh.mv. Welcome to the Java Programming Forums.
Do you know exactly how many lines there will be each time? Will there always be 1000 lines?
Re: File Reading from the specified location
I'm not sure if this will work as expected but try this:
Code :
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class FileReader {
/**
* JavaProgrammingForums.com
*/
public static int lineNumber;
public static String myFile = "inputfile.txt";
public void doStuff() {
switch (lineNumber) {
case 100:
System.out.println("100 lines");
break;
case 200:
System.out.println("200 lines");
break;
case 300:
System.out.println("300 lines");
break;
case 400:
System.out.println("400 lines");
break;
case 500:
System.out.println("500 lines");
break;
case 600:
System.out.println("600 lines");
break;
case 700:
System.out.println("700 lines");
break;
case 800:
System.out.println("800 lines");
break;
case 900:
System.out.println("900 lines");
break;
case 1000:
System.out.println("1000 lines");
break;
default:
break;
}
}
public void readMe() {
try {
FileInputStream in = new FileInputStream(myFile);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
//System.out.println(strLine);
lineNumber++;
doStuff();
}
} catch (Exception e) {
System.out.println("Problem reading file! " + e);
}
}
public static void main(String[] args) {
FileReader fr = new FileReader();
fr.readMe();
System.out.println("Total number of lines: " + lineNumber);
}
}
Re: File Reading from the specified location
I got the solution for that issue.Thanks for your replies