Hallo, ich habe bislang als Datenlieferant ein File das so aussah:
"
Stock Code
Stock Description
500
540
29
"
mit dem folgenden Code geht das auch sehr gut - keine Frage!
jetzt wird das System aber so umgestellt, dass die Daten mit Komma getrennt sind also so z.B.
"
Stock Code, Stock Description, 500, 540, 29
Stock Code, Stock Description, 520, 580, 31
"
ich schaffe es nicht das mit line.split(",") abzuändern - sollte doch möglich sein?
mir geht es darum das es als string und integer werte gelesen werden kann
Danke für die Hilfe!
"
Stock Code
Stock Description
500
540
29
"
mit dem folgenden Code geht das auch sehr gut - keine Frage!
Java:
import java.io.* ;
public class HexusProb {
/*Declare arrays, ten is arbitrary value */
static String[] StockCode = new String[10] ;
static String[] StockDesc = new String[10] ;
static int[] CurrentLevel = new int[10] ;
static int[] ReorderLevel = new int[10] ;
static float[] Price = new float[10] ;
public static void main(String[] args) {
try {
BufferedReader fileIn =
new BufferedReader(new FileReader(args[0]));
int count = 0 ;
String in = fileIn.readLine() ;
while(in!=null) {
StockCode[count] = in ;
StockDesc[count] = fileIn.readLine() ;
CurrentLevel[count] = Integer.parseInt(fileIn.readLine()) ;
ReorderLevel[count] = Integer.parseInt(fileIn.readLine()) ;
Price[count] = Float.parseFloat(fileIn.readLine()) ;
in = fileIn.readLine() ;
count++ ; /* increment counter */
} /* End of while */
} catch(IOException ioe) {
ioe.printStackTrace() ;
}
displayRecords() ;
System.exit(0) ;
} /* End of main */
/* This prints out the arrays to the console */
public static void displayRecords() {
for (int i = 0 ; i <= (StockCode.length-1) ; i++) {
if(StockCode[i]==null)
return ; /* end of useful data */
System.out.print("\t"+StockCode[i]);
System.out.print("\t\t"+StockDesc[i]);
System.out.print("\t\t"+CurrentLevel[i]);
System.out.print("\t\t"+ReorderLevel[i]);
System.out.print("\t\t"+Price[i]);
}
}
}
jetzt wird das System aber so umgestellt, dass die Daten mit Komma getrennt sind also so z.B.
"
Stock Code, Stock Description, 500, 540, 29
Stock Code, Stock Description, 520, 580, 31
"
ich schaffe es nicht das mit line.split(",") abzuändern - sollte doch möglich sein?
mir geht es darum das es als string und integer werte gelesen werden kann
Danke für die Hilfe!