我正在尝试读取txt文件并在data.xls文件中打印行。脚本在data.xls中打印了第一行6次(重复项),但是脚本未在data.xls文件中打印下一行。 records.txt中共有6行
这是我的records.txt文件的外观,如下所示:
"Userid","Subscriberid"
"167fgfg611","5904fds02"
"200fhskdhf","876fsgj25"
"3893fjs956","502sgfgg3"
"918shdfd71","1029gsg57"
Record Count: 4
运行以下脚本后,data.xls显示如下:
"Userid","Subscriberid"
"Userid","Subscriberid"
"Userid","Subscriberid"
"Userid","Subscriberid"
"Userid","Subscriberid"
"Userid","Subscriberid"
以下是我的代码:
String st;
int line;
BufferedReader Br = null;
File objFile = new File(
"C:\\DATA\\records.txt");
Br = new BufferedReader(new FileReader(objFile));
while ((st = Br.readLine()) != null) {
LineNumberReader lineNumberReader = new LineNumberReader(new FileReader(objFile));
lineNumberReader.skip(Long.MAX_VALUE);
int lines = lineNumberReader.getLineNumber();
lines++;
String value = st.replace("\"", "");
arraylist = value.split(",");
FileOutputStream outFile1 = new FileOutputStream(
new File("C:\\DATA\\userdata.xls"));
Workbook book = new HSSFWorkbook();
Sheet sheet = book.createSheet("UserData");
Row row = null;
Cell cell = null;
for (line = 0; line < lines; line++) {
row = sheet.createRow(line);
for (int i = 0; i < arraylist.length; i++) {
cell = row.createCell(i);
cell.setCellValue(arraylist[i]);
}
}
book.write(outFile1);
outFile1.close();
Br.close();
}
答案 0 :(得分:0)
我在循环中做错了。最初,我在循环中保留以下代码:
gui_open_db -file ./vcdplus.vpd
gui_open_window Wave
gui_sg_create abc
gui_list_add_group -id Wave.1 { abc }
gui_sg_addsignal -group abc {
top.dut_inst.xyz.mno
{top.dut_inst.xyz.pqr[3][7:0]}
}
gui_zoom -window Wave.1 -full
在从While循环中删除上述代码并将其保留在while循环之外之后,我还从代码中删除了FileOutputStream outFile1 = new FileOutputStream(
new File("C:\\DATA\\data.xls"));
Workbook book = new HSSFWorkbook();
LineNumberReader lineNumberReader = new LineNumberReader(new FileReader(objFile));
lineNumberReader.skip(Long.MAX_VALUE);
int lines = lineNumberReader.getLineNumber();
Sheet sheet = book.createSheet("UserData");
循环,这使我的代码可以正常工作。
以下是我更新的代码:
for (line = 0; line < lines; line++) {}