我想读取一个数据流,每次它读取某个单词或短语时,我都希望计数增加。我在下面的示例无法计算它。我也尝试寻找“回声百分比”。bat 文件所做的只是回显百分比。
try {
String ls_str;
String percent = "percent";
Process ls_proc = Runtime.getRuntime().exec("c:\\temp\\percenttest.bat");
// get its output (your input) stream
DataInputStream ls_in = new DataInputStream(ls_proc.getInputStream());
while ((ls_str = ls_in.readLine()) != null ) {
System.out.println(ls_str);
progressBar.setValue(progress);
taskOutput.append(String.format(ls_str+"\n", progress));
if (ls_str == percent) {
progress++;
}
}
} catch (IOException e1) {
System.out.println(e1.toString());
e1.printStackTrace();
}
setProgress(Math.min(progress, 100));