从属性读取时找不到文件异常

时间:2016-01-15 07:26:49

标签: java filenotfoundexception

我在从emailconfig.cfg读取ost_file_path时面临以下错误,使用属性加载读取配置文件,但是当我对文件进行硬编码时,它在读取文件时没有任何问题。

收到异常

java.io.FileNotFoundException: "C:\Users\gcothak2\AppData\Local\Microsoft\Outlook\gopala.cothakotai@credit-suisse.com - Default Outlook Profile.ost" (The filename, directory name, or volume label syntax is incorrect)
    at java.io.RandomAccessFile.open(Native Method)
    at java.io.RandomAccessFile.<init>(RandomAccessFile.java:241)
    at com.pff.PSTFile.<init>(PSTFile.java:125)
    at com.pff.PSTFile.<init>(PSTFile.java:119)
    at com.test.programs.EmailReadProcess.EmailReadExecute(EmailReadProcess.java:86)
    at com.test.programs.EmailReadProcess.main(EmailReadProcess.java:75)

ost_file_path

的手动硬编码
//String filename  = "C:\\Users\\gcothak2\\AppData\\Local\\Microsoft\\Outlook\\gopala.cothakotai@credit-suisse.com - Default Outlook Profile.ost";

EmailConfig.cfg

FOLDERS_TO_SEARCH = "Inbox|SDO"

SUBJECT_TO_SEARCH = "^CLOCK CONTRACT FILE$"

OST_FILE_PATH = 

    "C:\\Users\\gcothak2\\AppData\\Local\\Microsoft\\Outlook\\gopala.cothakotai\@debit-base.com - Default Outlook Profile.ost"

FOLDERS_SEPARATOR_DELIM = "|"

RERUN_ONCE_AGAIN = true

TIME_TO_RUN = 16:00

ATTACHMENT_DOWNLOAD_PATH = "M:\\tempReports" 

RERUN_ONCE_AGAIN=true

EmailReadProcess.java

public void readFromConfig(String filename) throws Exception {

    //path of the class file
    String filepath = EmailReadProcess.class.getProtectionDomain().getCodeSource().getLocation().getPath();

    //String filepath = "M:\\Documents\\workspace-sts-3.7.0.RELEASE\\LDODashBoard\\target\\classes";

    //path of the config file
    configFilename = filename;

    props.load(new FileInputStream(filepath + "\\"+ configFilename));

    //it will be separated by pile delimited
    foldersToSearch = props.getProperty("FOLDERS_TO_SEARCH");
    subjectToSearch = props.getProperty("SUBJECT_TO_SEARCH");
    ostFilepath = props.getProperty("OST_FILE_PATH");
    foldersSearchDelim = props.getProperty("FOLDERS_SEPARATOR_DELIM");

    System.out.println("filepath:"  + filepath);
    System.out.println("configFilename:"  + configFilename);



    System.out.println("foldersSearchDelim:"  + foldersSearchDelim);

    if (props.getProperty("RERUN_ONCE_AGAIN").equalsIgnoreCase("true")){
        rerunOnceAgain = true;
    }
    else{
        rerunOnceAgain = false;
    }

    //eg: 16:00 or 09:01 
    timeToRun = props.getProperty("TIME_TO_RUN");
    attachDownloadPath = props.getProperty("ATTACHMENT_DOWNLOAD_PATH");

    foldersInList = convertFoldersToList();
}

public static void main(String[] args)
{
    //String filename  = "C:\\Users\\gcothak2\\AppData\\Local\\Microsoft\\Outlook\\gopala.cothakotai@credit-suisse.com - Default Outlook Profile.ost";
    //new EmailReadProcess(args[0]);

    String filename = "TSEEmailconfig.cfg";
    EmailReadProcess emailProcess = new EmailReadProcess();

    try {
        emailProcess.readFromConfig(filename);
        emailProcess.EmailReadExecute();
    }
    catch(Exception e){
        e.printStackTrace();
    }

}

public void EmailReadExecute() {
    try {
        //ostFilepath = "C:\\Users\\gcothak2\\AppData\\Local\\Microsoft\\Outlook\\gopala.cothakotai@credit-suisse.com - Default Outlook Profile.ost";
        PSTFile pstFile = new PSTFile(ostFilepath);
        System.out.println(pstFile.getMessageStore().getDisplayName());
        processFolder(pstFile.getRootFolder());
    } catch (Exception err) {
        err.printStackTrace();
    }
}

0 个答案:

没有答案