Hi, I would like to know where I am wrong in this java code, I state that already BAX the code works as below,
Error
Impossibile copiare ita traineddatajava.io.FileNotFoundException: /data/user/0/b4a.example/files/ita.traineddata (No such file or directory)
Error
Impossibile copiare ita traineddatajava.io.FileNotFoundException: /data/user/0/b4a.example/files/ita.traineddata (No such file or directory)
If File.IsDirectory(File.DirRootExternal,"tessdata") = False Then
' File.MakeDir(File.DirRootExternal, "tessdata")
' tessDataPath = File.DirRootExternal & "/tessdata"
' 'Copy Trainned Files to RootDir
' Dim fList As List = File.ListFiles(File.DirAssets)
' Dim fileName As String
' For i=0 To fList.Size-1
' fileName = fList.Get(i)
' If fileName.ToLowerCase.Contains("eng.traineddata") Then
' If File.Exists(tessDataPath,fileName)=False Then
' File.Copy(File.DirAssets,fileName, tessDataPath, fileName)
' End If
' End If
' Next
' End If
public void TessOCR() {
String[] paths = new String[]{TESSERACT_PATH + "tessdata/"};
for (String path : paths) {
File dir = new File(path);
if (!dir.exists()) {
if (!dir.mkdirs()) {
BA.Log("ERROR: Creation of directory" +path);
return;
} else {
BA.Log("Created directory"+ path);
}
}
}
if (!(new File(TESSERACT_PATH + "tessdata/" + DEFAULT_LANGUAGE + ".traineddata")).exists()) {
try {
String gifname = DEFAULT_LANGUAGE + ".traineddata";
BA.Log("Nome File "+ gifname);
// InputStream in = mContext.getAssets().open("tessdata/" + DEFAULT_LANGUAGE + ".traineddata");
InputStream in = new BufferedInputStream(new FileInputStream(new File(anywheresoftware.b4a.objects.streams.File.getDirAssets(),
gifname.toLowerCase(BA.cul))));
//InputStream in = new BufferedInputStream(new FileInputStream(new File(anywheresoftware.b4a.objects.streams.File.getDirAssets(), gifname.toLowerCase(BA.cul))));
OutputStream out = new FileOutputStream(new File(TESSERACT_PATH + "tessdata/", DEFAULT_LANGUAGE + ".traineddata"));
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) != -1) {
out.write(buf, 0, len);
}
in.close();
out.close();
BA.Log("Copied " + DEFAULT_LANGUAGE + " traineddata");
} catch (IOException e) {
BA.Log("Impossibile copiare " + DEFAULT_LANGUAGE + " traineddata"+e.toString());
}
}
/*
mTess = new TessBaseAPI();
mTess.setDebug(true);
mTess.init(DATA_PATH, lang);
*/