Java.io.filenotfoundexception文件路径(访问被拒绝)

时间:2017-08-10 05:30:00

标签: java file-handling java-io

我制作了.exe文件(使用launchj4和inno install creater)。在java文件(Netbeans Project)中,它可以正常工作,我可以编辑和更改数据,但是当我尝试在exe文件中使用它时,它会给出Exception,它只读取文件。

它还显示了Customer.txt和其他2的确切路径,但是当我尝试编写它时:

  

java.io.FileNotFoundException C:\ Program Files(x86)\ MyApp \ Customer.txt(拒绝访问)

代码:

public DataInOut()
    {
    customer = new File("Customer.txt");
    Sale = new File("SaleReport.txt");
    Salesman = new File("SaleMan.txt");
    path_Customer = customer.getAbsolutePath();
    path_Sale = Salesman.getAbsolutePath();
    path_Report = Sale.getAbsolutePath();
    WriteCustomer = new File(path_Customer);
    WriteSale = new File(path_Report);
    WriteSalesMan = new File(path_Sale);
}

public void dataIn()
{
    try{
        int i =0;
        CR = new FileReader(customer);
        CBR = new BufferedReader(CR);
        boolean check = true;
        while(check)
        {
                String text = CBR.readLine();
                if(text!=null)
                {
                    String[] arr = text.split("=");
                    int index = Integer.parseInt(arr[5]);
                    arr_customer[index] = text;
                    arr_index[i] = index;
                    i++;
                }
                else
                    check = false;
        }
        CBR.close();
        CR.close();

        i = 0;
        SaleR = new FileReader(Sale);
        SaleBR = new BufferedReader(SaleR);
        check = true;
        while(check)
        {
            String text = SaleBR.readLine();
            if(text!=null)
            {
                arr_report[i] = text;
                i++;
            }
            else
                check = false;
        }
        SaleBR.close();
        SaleR.close();
        i = 0;
        SR = new FileReader(Salesman);
        SBR = new BufferedReader(SR);
        check = true;
        while(check)
        {
            String text = SBR.readLine();
            if(text!=null)
            {
                arr_Saleman[i] = text;
                i++;
            }
            else
                check = false;
        }
        SBR.close();
        SR.close();
    }catch(Exception e)
    {
        JOptionPane.showMessageDialog(null, e);
    }
}

public void dataOut()
{
    try{
        int i = 0;
        FileWriter fw = new FileWriter(WriteCustomer,false);
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write("");
        bw.close();
        fw.close();

        CW = new FileWriter(WriteCustomer,true);
        CBW = new BufferedWriter(CW);
        CBW.flush();
        while(arr_index[i]!=0)
        {
            CBW.write(arr_customer[arr_index[i]]);
            CBW.newLine();
            i++;
        }
        CBW.close();
        CW.close();


        FileWriter fw2 = new FileWriter(WriteSale,false);
        BufferedWriter bw2 = new BufferedWriter(fw2);
        bw2.write("");
        bw2.close();
        fw2.close();
        i = 0;
        SaleW = new FileWriter(WriteSale,true);
        saleBW = new BufferedWriter(SaleW);
        saleBW.flush();
        while(arr_report[i]!=null)
        {
            saleBW.write(arr_report[i]);
            saleBW.newLine();
            i++;
        }
        saleBW.close();
        SaleW.close();

        FileWriter fw3 = new FileWriter(WriteSalesMan,false);
        BufferedWriter bw3 = new BufferedWriter(fw2);
        bw3.write("");
        bw3.close();
        fw3.close();
        i = 0;
        SW = new FileWriter(WriteSalesMan,true);
        SBW = new BufferedWriter(SW);
        SBW.flush();
        while(arr_Saleman[i]!=null)
        {
            SBW.write(arr_Saleman[i]);
            SBW.newLine();
            i++;
        }
        SBW.close();
        SW.close();
        JOptionPane.showMessageDialog(null, "Done");
    }catch(Exception e)
    {
        JOptionPane.showMessageDialog(null, e);
    }
}

0 个答案:

没有答案