पढ़ और लिखना मैं 2 सीएसवी फाइलें पढ़ रहा हूं: store_inventory
& new_acquisitions
।
मैं सीएसवी फ़ाइल की तुलना new_acquisitions
से तुलना करने में सक्षम होना चाहता हूं। 1) यदि आइटम नाम मिलान केवल store_inventory में मात्रा को अद्यतन करते हैं। 2) यदि new_acquisitions में एक नया आइटम है जो store_inventory
में मौजूद नहीं है, तो इसे store_inventory
पर जोड़ें।जावा: सीएसवी फ़ाइल
यहां मैंने जो किया है, लेकिन यह बहुत अच्छा नहीं है। मैंने टिप्पणियां जोड़ दीं जहां मुझे & जोड़ने की आवश्यकता है।
उपरोक्त कार्यों को करने के लिए कोई सलाह या कोड बहुत अच्छा होगा! धन्यवाद।
File new_acq = new File("/src/test/new_acquisitions.csv");
Scanner acq_scan = null;
try {
acq_scan = new Scanner(new_acq);
} catch (FileNotFoundException ex) {
Logger.getLogger(mainpage.class.getName()).log(Level.SEVERE, null, ex);
}
String itemName;
int quantity;
Double cost;
Double price;
File store_inv = new File("/src/test/store_inventory.csv");
Scanner invscan = null;
try {
invscan = new Scanner(store_inv);
} catch (FileNotFoundException ex) {
Logger.getLogger(mainpage.class.getName()).log(Level.SEVERE, null, ex);
}
String itemNameInv;
int quantityInv;
Double costInv;
Double priceInv;
while (acq_scan.hasNext()) {
String line = acq_scan.nextLine();
if (line.charAt(0) == '#') {
continue;
}
String[] split = line.split(",");
itemName = split[0];
quantity = Integer.parseInt(split[1]);
cost = Double.parseDouble(split[2]);
price = Double.parseDouble(split[3]);
while(invscan.hasNext()) {
String line2 = invscan.nextLine();
if (line2.charAt(0) == '#') {
continue;
}
String[] split2 = line2.split(",");
itemNameInv = split2[0];
quantityInv = Integer.parseInt(split2[1]);
costInv = Double.parseDouble(split2[2]);
priceInv = Double.parseDouble(split2[3]);
if(itemName == itemNameInv) {
//update quantity
}
}
//add new entry into csv file
}
किसी भी मदद के लिए धन्यवाद। =]
आप अधिक और बेहतर जवाब पाने यदि आप वास्तव में एक सवाल पूछ मिल जाएगा। –