csv ファイルからデータを読み込み、データベースに保存したいと考えています。これは、csvファイルを保存した方法です(これはエラーなしで機能します-CSVreaderで読み取る予定のファイルがどこにどのように保存されているかを示すためだけです):
synchronized public void readFromUrl(String url, String outputFile, Context context) throws FileNotFoundException {
URL downloadLink = null;
try {
downloadLink = new URL(url);
} catch (MalformedURLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
BufferedReader in = null;
try {
in = new BufferedReader(
new InputStreamReader(downloadLink.openStream(), "UTF8"));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
FileOutputStream fstream = context.openFileOutput(outputFile,Context.MODE_PRIVATE);
Writer out = new OutputStreamWriter(fstream);
Log.d(TAG, "BufferedReader "+in);
String inputLine = null;
try {
while ((inputLine = in.readLine()) != null){
out.write(inputLine+"\n");
//logger.debug("DOWNLOADED: "+inputLine);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
fstream.close();
out.close();
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
csvファイルを読み取るためのこれまでの私のコード:
public void readInCSVFile(String filename, Context context) throws IOException {
IDbHelper dbHelper = new DbHelper(); ;
CSVReader products = null;
products = new CSVReader(new InputStreamReader(context.getAssets().open(filename)));
NoClassDefFoundError 例外が発生します。
Android プロジェクトの参照ライブラリに opencsv.jar があります。
よろしくお願いします。