我有.csv文件"推销员"将上传到sqlite数据库。此文件包含有关推销员的详细信息。
Salesman的示例行:
-----------
|code|name|
-----------
|0001|Jon|
-----------
|0002|Stu|
销售员的DDL:
CREATE TABLE salesman (
code INTEGER NOT NULL,
name TEXT NOT NULL,
isSelected INTEGER NOT NULL,
PRIMARY KEY (
code
)
);
属性isSelected
充当标签,表明已选择推销员,因此无法再次选择。
这是我从.CSV文件中获取销售员详细信息的代码:
public static ArrayList<Salesman> getSalesmanFromFile(String filePath){
ArrayList<Salesman> salesmanList= new ArrayList<Salesman>();
try {
BufferedReader br = new BufferedReader(new FileReader(filePath));
String line = null;
String[] strSalesman = null;
try {
while ((line=br.readLine()) != null){
strSalesman = line.split(",");
salesmanList.add(new Salesman(Integer.parseInt(strSalesman[0]), strSalesman[1]));
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
String status = "Error"; //- Please review file selected. Make sure that format is followed.";
}
return salesmanList;
}
我的问题是,如何将方法中的第三个属性isSelected
设置为0(未选中)?由于.csv文件不包含标记属性,我想将其放在上面的方法中(将在整个程序的开头使用)。
我想在方法int isSelected = 0
中创建变量,但我不知道如何将其与BufferedReader
合并。类似的东西:
BufferedReader br = new BufferedReader(new FileReader(filePath));
String line = null;
String[] strSalesman = null;
//int isSelected = 0;
try {
while ((line=br.readLine()) != null){
strSalesman = line.split(",");
salesmanList.add(new Salesman(Integer.parseInt(strSalesman[0]), strSalesman[1], isSelected?));
}
} catch (IOException ex) {
ex.printStackTrace();
}
任何帮助将不胜感激!