Java jar 可执行文件无法读取 dropbox 上的 excel 个文件
Java jar executable cannot read excel files on dropbox
有点复杂的问题。
我有一个程序可以使用 XSSFSheets 从 excel 文件中读取数据。一切正常。
我遇到的问题是,对于某些用户来说,如果文件位于 Dropbox 上,程序将无法运行。 (本地版本的 Dropbox,在他们的硬盘上。)
问题与路径无关。检查的次数多得我数不过来。
奇怪的是,每个人对 dropbox 和 office 365 的管理员权限完全相同。到目前为止我能找到的唯一区别是这些用户有 windows 10 个。
如果我们将这些 excel 文件放在桌面上,程序可以找到它们。
有谁知道 Java get excel sheets on dropbox 是否出于任何原因有问题?它与 windows 10 resp windows 8 有什么关系吗?如果是这样,为什么它可以在 windows 10 桌面上运行。
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JFrame;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class xlmsReader {
public static ArrayList<XSSFSheet> fileReader() {
String directPath = System.getProperty("user.dir");
//removing the folder name, search through all folders in the parent folder, regardless of the location of the program folder.
directPath = directPath.substring(0, directPath.length()-18);
File[] directories = new File(directPath).listFiles(File::isDirectory);
ArrayList<XSSFSheet> excel = new ArrayList<XSSFSheet>();
for (int j = 0; j < directories.length; j++) {
if (new File(directories[j] + "\Groning.xlsm").exists()) {
String str = directories[j] + "\Groning.xlsm";
FileInputStream file;
file = null;
try {
file = new FileInputStream(new File(str));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
XSSFWorkbook workbook;
workbook = null;
try {
workbook = new XSSFWorkbook(file);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
XSSFSheet sheet = workbook.getSheet("Gröning");
sheet.getRow(0).getCell(0).setCellValue(directories[j].getPath());
excel.add(sheet);
}
}
return excel;
}
}
大家好回答。
我终于找到问题所在了。
运行 只是 Java JRE 的计算机无法 运行 程序。
运行 Java JDK 可以的计算机。所以看起来我使用了一些仅供开发人员使用的功能。我不知道具体是什么,但是问题已经解决了,所以我不会再投入更多精力了。
有点复杂的问题。
我有一个程序可以使用 XSSFSheets 从 excel 文件中读取数据。一切正常。
我遇到的问题是,对于某些用户来说,如果文件位于 Dropbox 上,程序将无法运行。 (本地版本的 Dropbox,在他们的硬盘上。)
问题与路径无关。检查的次数多得我数不过来。
奇怪的是,每个人对 dropbox 和 office 365 的管理员权限完全相同。到目前为止我能找到的唯一区别是这些用户有 windows 10 个。
如果我们将这些 excel 文件放在桌面上,程序可以找到它们。
有谁知道 Java get excel sheets on dropbox 是否出于任何原因有问题?它与 windows 10 resp windows 8 有什么关系吗?如果是这样,为什么它可以在 windows 10 桌面上运行。
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JFrame;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class xlmsReader {
public static ArrayList<XSSFSheet> fileReader() {
String directPath = System.getProperty("user.dir");
//removing the folder name, search through all folders in the parent folder, regardless of the location of the program folder.
directPath = directPath.substring(0, directPath.length()-18);
File[] directories = new File(directPath).listFiles(File::isDirectory);
ArrayList<XSSFSheet> excel = new ArrayList<XSSFSheet>();
for (int j = 0; j < directories.length; j++) {
if (new File(directories[j] + "\Groning.xlsm").exists()) {
String str = directories[j] + "\Groning.xlsm";
FileInputStream file;
file = null;
try {
file = new FileInputStream(new File(str));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
XSSFWorkbook workbook;
workbook = null;
try {
workbook = new XSSFWorkbook(file);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
XSSFSheet sheet = workbook.getSheet("Gröning");
sheet.getRow(0).getCell(0).setCellValue(directories[j].getPath());
excel.add(sheet);
}
}
return excel;
}
}
大家好回答。
我终于找到问题所在了。
运行 只是 Java JRE 的计算机无法 运行 程序。
运行 Java JDK 可以的计算机。所以看起来我使用了一些仅供开发人员使用的功能。我不知道具体是什么,但是问题已经解决了,所以我不会再投入更多精力了。