如何检查文件路径是否存在

时间:2017-04-08 19:01:51

标签: java filepath java-io

我正在编写一个代码,询问文件路径是否为空。如果路径为null,我需要返回false。我遇到的问题是该方法没有返回false。我无法判断该方法是否检查filePath是否存在。这是我的代码:

public boolean saveWordTable(List<Word> wordTable, String filePath) throws IOException {
    FileOutputStream fos = new FileOutputStream(new File(filePath));
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    if (wordTable == null) {
        return false;
    }
    if (!(new File(filePath).exists())) {
        return false;
    }


    try {
        oos.writeObject(wordTable);
    } catch (IOException e) {
        //e.printStackTrace();
        return false;
    }

    fos.close();
    oos.close();
    return true;

任何形式的帮助都将受到赞赏。

0 个答案:

没有答案
相关问题