Java jar可执行文件无法读取dropbox

时间:2018-02-09 10:25:36

标签: java excel dropbox executable-jar

有点复杂的问题。

我有一个使用XSSFSheets从excel文件中读取数据的程序。一切正常。

我遇到的问题是,对于某些用户,如果文件位于Dropbox上,则该程序不起作用。 (Dropbox的本地版本,在他们的硬盘上。)

问题与路径无关。检查次数超过我的数量。

奇怪的是,每个人对dropbox和office 365都拥有完全相同的管理权限。到目前为止我唯一能找到的区别就是这些用户拥有Windows 10。

如果我们将这些excel文件放在桌面上,程序就可以找到它们。

有没有人知道Java是否因为任何原因而在dropbox上出现excel表?它可以与windows 10 resp windows 8有什么关系吗?如果是这样,为什么它可以在Windows 10桌面上运行。

2 个答案:

答案 0 :(得分:0)

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;
    }
}

答案 1 :(得分:0)

大家回答。

我终于发现了什么是错的。

仅运行Java JRE的计算机无法运行该程序。

运行Java JDK的编译器可以。所以我似乎已经使用了一些仅适用于开发人员的功能。我不知道究竟是什么,但问题已经解决了,所以我不会为此付出更多的努力。