我正在尝试复制Tesseract文件以供使用,无论我如何尝试它都会一直给我找不到文件的异常。我不明白为什么,因为我把它们放在assets文件夹中。我通过复制特定的tessdata文件夹尝试了一种方法,因为我尝试将它们全部放在一般资源文件夹下,然后将每个文件复制到我在名为tessdata的卡片上创建的新目录中。
这是文件夹中文件的图像,复制方法和发布的日志错误:
这是代码:
private void copyAssets() {
AssetManager assetManager = getAssets();
String[] files = null;
try {
files = assetManager.list("");
} catch (IOException e) {
android.util.Log.e(TAG, "Failed to get asset file list.", e);
}
for(String filename : files) {
InputStream in = null;
OutputStream out = null;
try {
in = assetManager.open(filename);
out = new FileOutputStream(tesspath+ "/" + filename);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch(IOException e) {
android.util.Log.e("tag", "Failed to copy asset file: " + filename, e);
}
}
}
- 我也试过在一个例子中使用这个方法,该例子从资产中的tessdata文件夹中复制它们 -
if (!(new File(tesspath + File.separator + lang + ".traineddata")).exists()) {
copyAssets();
/* try {
AssetManager assetManager = getAssets();
//open the asset manager and open the traineddata path
InputStream in = assetManager.open("tessdata/eng.traineddata");
android.util.Log.e(TAG, "OPENED SUCCESSFULLY IF NO ERROR BEFORE THIS");
OutputStream out = new FileOutputStream(tesspath + "/eng.traineddata");
android.util.Log.e(TAG, "WRITING NOW TO" + tesspath);
byte[] buf = new byte[8024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
} catch (IOException e) {
android.util.Log.e(TAG, "Was unable to copy " + lang
+ " traineddata " + e.toString());
android.util.Log.e(TAG, "IM PRINTING THE STACK TRACEs");
e.printStackTrace();
}
*/
} else {
processImage(STORAGE_PATH + File.separator + "savedAndroid.jpg");
}
答案 0 :(得分:0)
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />