是否有任何内置方法可以让用户从当前运行的JAR中提取文件并将其保存在磁盘上?
提前致谢.
我正在使用tess4j,Tesseract的java包装器.我也安装了正常的Tesseract.我不太确定tess4j是如何工作的,但由于它附带了一个tessdata文件夹,我可以假设您将语言数据文件放在那里.但是,tess4j仅在语言数据文件位于"真实"tessdata文件夹(tesseract附带的文件夹,而不是tess4j)中时才起作用.如果我删除该文件夹,我收到此错误消息:
Error opening data file C:\Program Files\Tesseract-OCR\tessdata/jpn.trained
data
Please make sure the TESSDATA_PREFIX environment variable is set to the par
ent directory of your "tessdata" directory.
Failed loading language 'jpn'
Tesseract couldn't load any languages!
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x631259dc, pid=5108, tid=
10148
#
# JRE version: 7.0_06-b24
# Java VM: Java HotSpot(TM) Client VM (23.2-b09 mixed mode, sharing windows
-x86 )
# Problematic frame:
# …Run Code Online (Sandbox Code Playgroud) 我有一个.jar,它有两个依赖的.dll文件.我想知道是否有任何方法可以将这些文件从.jar中复制到运行时的用户临时文件夹中.这是我当前的代码(编辑为只有一个.dll加载以减少问题大小):
public String tempDir = System.getProperty("java.io.tmpdir");
public String workingDir = dllInstall.class.getProtectionDomain().getCodeSource().getLocation().getPath();
public boolean installDLL() throws UnsupportedEncodingException {
try {
String decodedPath = URLDecoder.decode(workingDir, "UTF-8");
InputStream fileInStream = null;
OutputStream fileOutStream = null;
File fileIn = new File(decodedPath + "\\loadAtRuntime.dll");
File fileOut = new File(tempDir + "loadAtRuntime.dll");
fileInStream = new FileInputStream(fileIn);
fileOutStream = new FileOutputStream(fileOut);
byte[] bufferJNI = new byte[8192000013370000];
int lengthFileIn;
while ((lengthFileIn = fileInStream.read(bufferJNI)) > 0) {
fileOutStream.write(bufferJNI, 0, lengthFileIn);
}
//close all steams
} catch (IOException e) { …Run Code Online (Sandbox Code Playgroud)