我有一个名为“and.doc”的文件,其中有大量记录,每个记录都具有以下形式:
expression:definition;
因此,我正在尝试:
- 使用扫描仪读取文件
- 使用
;
作为分隔符 - 找到一种方法将expression从definition中分离出来
- 并以某种方式将它们添加到我的Sqlite数据库中(如果有人有任何想法如何做到这一点,那将是很棒的)。
我正在使用这段代码:
try {
mf =new File("/home/agh/AndroidStudioProjects/Dicod/app/src/main/res/raw/and.doc");
inputFile = new Scanner(mf);
inputFile.useDelimiter(";");
while (inputFile.hasNext())
{
String x = inputFile.next();
Toast.makeText(getApplicationContext(),x,Toast.LENGTH_LONG).show();
//Splitting and adding to the databse
}
}
catch(FileNotFoundException e) {
e.printStackTrace();
}`
但我一直收到这个错误。
06-23 04:38:28.771 23620-23620/? W/System.err: java.io.FileNotFoundException: /home/agh/AndroidStudioProjects/Dicod/app/src/main/res/raw/and.txt: open failed: ENOENT (No such file or directory)
06-23 04:38:28.771 23620-23620/? W/System.err: at libcore.io.IoBridge.open(IoBridge.java:465)
06-23 04:38:28.771 23620-23620/? W/System.err: at java.io.FileInputStream.<init>(FileInputStream.java:76)
06-23 04:38:28.771 23620-23620/? W/System.err: at java.util.Scanner.<init>(Scanner.java:158)
06-23 04:38:28.772 23620-23620/? W/System.err: at java.util.Scanner.<init>(Scanner.java:138)
06-23 04:38:28.772 23620-23620/? W/System.err: at com.example.agh.dicod.MainActivity.onCreate(MainActivity.java:28)
06-23 04:38:28.772 23620-23620/? W/System.err: at android.app.Activity.performCreate(Activity.java:5990)
06-23 04:38:28.772 23620-23620/? W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
06-23 04:38:28.772 23620-23620/? W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332)
06-23 04:38:28.772 23620-23620/? W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
06-23 04:38:28.772 23620-23620/? W/System.err: at android.app.ActivityThread.access$800(ActivityThread.java:156)
06-23 04:38:28.772 23620-23620/? W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
06-23 04:38:28.772 23620-23620/? W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
06-23 04:38:28.772 23620-23620/? W/System.err: at android.os.Looper.loop(Looper.java:211)
06-23 04:38:28.772 23620-23620/? W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5389)
06-23 04:38:28.772 23620-23620/? W/System.err: at java.lang.reflect.Method.invoke(Native Method)
06-23 04:38:28.772 23620-23620/? W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
06-23 04:38:28.772 23620-23620/? W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
06-23 04:38:28.772 23620-23620/? W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
06-23 04:38:28.772 23620-23620/? W/System.err: Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
06-23 04:38:28.773 23620-23620/? W/System.err: at libcore.io.Posix.open(Native Method)
06-23 04:38:28.773 23620-23620/? W/System.err: at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
06-23 04:38:28.773 23620-23620/? W/System.err: at libcore.io.IoBridge.open(IoBridge.java:451)
06-23 04:38:28.773 23620-23620/? W/System.err: ... 17 more