I have following piece of code :
File file = new File("//path/to/BatchFile");
long fileLength = 0 ;
if(file.exists()){
fileLength = file.length();
}
Process process = Runtime.getRuntime().exec("cmd /c " + "//path/to/batchfile");
InputStream inputStream = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
String s;
long bytesRead=0;
while (( s = br.readLine()) != null) {
bytesRead = bytesRead + s.getBytes().length + 2; // forget about +2
int progress = (int) (( bytesRead/ fileLenth)*100 );
System.out.println("Progress : "+ progress);
}
What I am trying to do is running a batch file and converting it to BufferedReader to calculate the percentage for progress bar. But my percentage goes beyond 100.
Help me correcting what i am doing wrong or let me know how to convert the 'process' part into percentage.