안녕하세요 여러분 .CSV 파일을 읽고 XML로 구문 분석 할 파서 코드를 작성하고 있습니다. 이것은 내가 가진 코드이며 파일의 첫 번째 줄을 건너 뛰고 싶을 때만 작동합니다. 그래서는 HashMap을 설정하기로 결정하지만 제대로 작동 않습니다Java에서 CSV 파일을 읽는 중 첫 번째 줄 건너 뛰기
for (int i = 0; i < listOfFiles.length; i++) {
File file = listOfFiles[i];
if (file.isFile() && file.getName().endsWith(".csv")){
System.out.println("File Found: " + file.getName());//Prints the name of the csv file found
String filePath = sourcepath + "\\" + file.getName();
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
int n = 1;
Map<Integer,String> lineMap = new HashMap<Integer,String>();
int k=2;
while ((line = br.readLine()) != null) {
System.out.println(n + " iteration(s) of 1st While Loop");
lineMap.put(k, line);
fw.write(" <ASSET action=\"AddChange\">\n");
fw.write(" <HOSTNAME>\n");
hostName=line.substring(0, line.indexOf(","));
fw.append(hostName);
fw.write("</HOSTNAME>\n");
fw.write(" <HOSTID>\n");
hostID=line.substring(line.indexOf(",")+1, nthOccurrence(line, ',', 1));
fw.append(hostID);
fw.write("</HOSTID>\n");
fw.write(" <MACMODEL>\n");
machineModel=line.substring(nthOccurrence(line, ',', 1)+1, nthOccurrence(line, ',', 2));
fw.append(machineModel);
fw.write("</MACMODEL>\n");
fw.write(" <PROMODEL>\n");
processorModel=line.substring(nthOccurrence(line, ',', 2)+1, nthOccurrence(line, ',', 3));
fw.append(processorModel);
fw.write("</PROMODEL>\n");
fw.write(" <CORE>\n");
core=line.substring(nthOccurrence(line, ',', 3)+1, nthOccurrence(line, ',', 4));
fw.append(core);
fw.write("</CORE>\n");
fw.write(" <PROC>\n");
proc=line.substring(nthOccurrence(line, ',', 4)+1, nthOccurrence(line, ',', 5));
fw.append(proc);
fw.write("</PROC>\n");
fw.write(" <TIER>\n");
tier=line.substring(nthOccurrence(line, ',', 5)+1, nthOccurrence(line, ',', 6));
fw.append(tier);
fw.write("</TIER>\n");
fw.write(" <PRODNAME>\n");
productName=line.substring(nthOccurrence(line, ',', 6)+1, nthOccurrence(line, ',', 7));
fw.append(productName);
fw.write("</PRODNAME>\n");
fw.write(" <VERSION>\n");
version=line.substring(nthOccurrence(line, ',', 7)+1, nthOccurrence(line, ',', 8));
fw.append(version);
fw.write("</VERSION>\n");
fw.write(" <SCRIPTDATA>\n");
scriptData=line.substring(nthOccurrence(line, ',', 8)+1, line.length());
fw.append(scriptData);
fw.write("</SCRIPTDATA>\n");
fw.write(" </ASSET>\n");
k++;
}n++;
이 코드의 주요 부분의 조각입니다. 어떤 아이디어 또는 해결책 ???
유권자가 아니지만 '작동하는 것처럼 보입니다'라고 분명히 말하십시오. –
미안하지만 오히려 작동하지 않는 것 같습니다. – user2643355
우리는 그것을 알고 있습니다. 그러나 앞으로는 어떻게 작동하지 않는지에 대해 더 많이 알게 될 것입니다. 보다 유용한 정보를 제공할수록 질문에 쉽게 답변 할 수 있습니다. –