【发布时间】:2016-10-02 20:24:54
【问题描述】:
在 Python 中,全局变量 __file__ 是当前文件的完整路径。
System.getProperty("user.dir"); 似乎返回了当前工作目录的路径。
我想获取当前.java、.class或包文件的路径。
然后使用它来获取图像的路径。
我在 Netbeans 中的项目文件结构如下:
(来源:toile-libre.org)
更新以使用我选择的最佳答案中建议的代码:
// read image data from picture in package
try {
InputStream instream = TesseractTest.class
.getResourceAsStream("eurotext.tif");
bufferedImage = ImageIO.read(instream);
}
catch (IOException e) {
System.out.println(e.getMessage());
}
此代码用于tess4j的用法示例。
我的使用示例的完整代码是here。
【问题讨论】: