我正在尝试从文本文件中读取并将每一行放在一个节点中
该文件如下所示:
2000年;阿斯顿马丁;阿斯顿马丁; DB9;汽车; A
2001年;阿斯顿马丁;阿斯顿马丁; DB9;汽车; B
2002年;阿斯顿马丁;阿斯顿马丁; V8 VANTAGE; Car; C
2003年;阿斯顿马丁;阿斯顿马丁; V8 VANTAGE; Car; D
我想用“;”分隔该行,并将每个String放在节点
中的值中但链接仍然是空的
虽然在JAVA简单程序中这个链接列表代码表现良好 但阅读中有一个问题
Pleaaaase帮助
这是代码:
class node{
node next ;
node previous ;
String year ;
String company ;
String manufacture ;
String modelname;
String type ;
String owner;
}
public class MainActivity extends Activity {
node head = null ;
node tail = new node ();
node nn= null;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[]tokens = new String [5] ;
try{
FileInputStream fstream = new FileInputStream("config.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line="";
while ((line=br.readLine()) != null) {
tokens = line.split(";");
if (head==null){
head = new node ();
head.year=tokens[0];
head.company =tokens[1];
head.manufacture=tokens[2];
head.modelname =tokens[3];
head.type= tokens[4];
head.owner=tokens[5];
head.next = null;
head.previous=null;
tail=head;
}
else {
nn = new node ();
nn.year=tokens[0];
nn.company =tokens[1];
nn.manufacture=tokens[2];
nn.modelname =tokens[3];
nn.type= tokens[4];
nn.owner=tokens[5];
tail.next = nn ;
nn.previous = tail ;
tail=nn;
nn.next = null;
}
}
in.close();
}
catch (Exception e){//Catch exception if any
e.printStackTrace();
}