I am doing a project that requires me to copy all the information from txt file into array. The content of the txt is listed below. What i want here is that i want to grab all the names of goods and description into its arrays respectively.
GoodTitle Description
Gold The shiny stuff
Wheat What wheaties are made of
Wood To make more ships
Spices To disguise the taste of rotten food
Tobacco Smoko time
Coal To make them steam ships go
Coffee Wakes you up
Tea Calms you down
What I have done so far:
public void openFile()
{
ArrayList <String> ShippingTokens = new ArrayList<String>();
try{
FileInputStream fstream = new FileInputStream("D://Shipping.txt");
// Use DataInputStream to read binary NOT text.
BufferedReader br = new BufferedReader (new InputStreamReader (fstream));
String strline;
while ((strline = br.readLine()) != null){
strline = strline.trim();
if ((strline.length()!=0)) {
String[] Shippings = strline.split("//s+");
ShippingTokens.add(Shippings[TOKEN_COLUMN]);
}
}
for (String s : ShippingTokens) {
System.out.println(s);
}
in.close();
} catch (Exception e){
System.err.println("Error");
}
}