Im Moment habe ich eine Textdatei, die Folgendes:Wie teile ich eine Zeile in tex-Datei in Lesen/Schreiben?
1 Commercial & Enterprise 5 SLICE 59.99 IP MICRO
2 Commercial & Enterprise 5 SLICE 59.99 MULTI-USE SWITCH
.
.
.
.
18 Government & Military 6 TCP 15.00 TCP
ich die Linie zu spalten versuche so, dass ich die folgenden haben: zur Zeit
Product number: 18
Category: Government & Military
Product name: TCP
Units in stock: 6
Price: $15.00
Total value: $90.00
Fee: $4.50
Total value: $94.50
ich den folgenden Code haben:
while ((line = lineReader.readLine()) != null) {
StringTokenizer tokens = new StringTokenizer(line, "\t");
p = new ActionProduct();
add(p);
String category = p.getCategory();
String name = p.getName();
category = tokens.nextToken();
int item = p.getItem();
double price = p.getPrice();
int units = p.getUnits();
while (tokens.hasMoreTokens()) {
item = Integer.parseInt(tokens.nextToken());
price = Double.parseDouble(tokens.nextToken());
units = Integer.parseInt(tokens.nextToken());
}
System.out.println("Category: " + category);
System.out.println("Product number: " + item);
System.out.println("Product name: " + name);
System.out.println("Units in stock: "+ units);
System.out.println("Price: $" + String.format("%.2f", price));
System.out.println("Total value: $" + String.format("%.2f",p.value()));
System.out.println("Fee: $" + String.format("%.2f", p.fee()));
System.out.println("Total value: $" + String.format("%.2f", value()));
}
Und ich bin immer diese Ausgabe statt:
Category: 1 Commercial & Enterprise 5 SLICE 59.99 IP MICRO
Product number: 0
Product name: null
Units in stock: 0
Price: $0.00
Total value: $0.00
Fee: $0.00
Total value: $0.00
Category: 2 Commercial & Enterprise 5 SLICE 59.99 MULTI-USE SWITCH
Product number: 0
Product name: null
Units in stock: 0
Price: $0.00
Total value: $0.00
Fee: $0.00
Total value: $0.00
Also meine Fragen ... was muss ich tun, um die Linie zu spalten, so dass ich jeden Wert meiner Textil einzeln drucken kann ?? Vielen Dank im Voraus Jungs, würde wirklich eine Richtung zu schätzen wissen!
Hier ist meine Textdatei:
1 Commercial & Enterprise 5 SLICE 59.99 IP MICRO
2 Commercial & Enterprise 5 SLICE 59.99 MULTI-USE SWITCH
3 Commercial & Enterprise 4 SLICE 59.99 2100
4 Commercial & Enterprise 6 SLICE 59.99 IP
5 Commercial & Enterprise 4 HDX 45.00 HYBRID CARRIER
6 Commercial & Enterprise 10 TRANSip 45.00 IP Technology Suite
7 Commercial & Enterprise 5 GUI 30.00 LINK COMMAND SYS
8 Commercial & Enterprise 5 GUI 30.00 MAUI
9 Commercial & Enterprise 6 RCP 20.00 RCP
10 Government & Military 5 SLICE 60.00 IP MICRO
11 Government & Military 5 SLICE 60.00 MULTI-USE SWITCH
12 Government & Military 4 SLICE 60.00 2100
13 Government & Military 6 SLICE 55.00 IP
14 Government & Military 4 HDX.C 35.00 HYBRID CARRIER
15 Government & Military 10 TRANSip 30.00 IP Technology Suite
16 Government & Military 5 GUI 20.00 LINK COMMAND SYS
17 Government & Military 5 GUI 20.00 MAUI
18 Government & Military 6 TCP 15.00 TCP
Ist RegEx eine Option? – David
humm nein, ich muss eine FILE.txt verwenden – ShaunK
?? Entschuldigung, aber deine Antwort, dass du regex nicht benutzen kannst, weil du file.txt benutzen musst, macht keinen Sinn. Kennen Sie die regulären Ausdrücke und wofür werden sie verwendet? Wenn ja, erläutern Sie bitte, warum Sie sie nicht in einem 'String # split (...)' –