1
我正在尝试复制Tesseract的文件以供使用,无论我如何尝试,都会给我提供filenot发现的异常。我不明白为什么,因为我在资产文件夹中有他们。我尝试了一种方法,通过复制特定的tessdata文件夹不工作,因此我试图将它们全部放在常规资产文件夹下,并将其中的每个文件复制到名为tessdata的卡上创建的新目录中。将资产文件复制到SD卡(找不到文件)?
这里的文件夹中的文件,复印的方法和发布日志错误的图像:
而这里的代码:
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);
}
}
}
-I也尝试使用这种方法从一个从资产内的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");
}