में सीएसवी फ़ाइल पढ़ने के दौरान पहली पंक्ति छोड़ें अरे दोस्तों मैं एक .csv फ़ाइल पढ़ने के लिए एक पार्सर कोड लिख रहा हूं और इसे एक्सएमएल पर पार्स कर रहा हूं। यह मेरे पास कोड है और यह ठीक काम करता है सिवाय इसके कि मैं इसे फ़ाइल में पहली पंक्ति छोड़ना चाहता हूं। तो मैं एक HashMap स्थापित करने का फैसला, लेकिन यह काम करने के लिए प्रतीत होता है:जावा
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
काम नहीं कर रहा है हम जानते हैं कि, लेकिन भविष्य में, यह बताएं कि यह कैसे काम नहीं करता है। आपके द्वारा दी जाने वाली अधिक उपयोगी जानकारी, आपके प्रश्नों का उत्तर देना आसान होगा। –