public void mmuOpen_actionPerformed(ActionEvent e) {
        fcSelect.showOpenDialog(this);
        File file;
        FileReader in=null;
        try{
            file=new File(fcSelect.getSelectedFile().getParent());
            in=new FileReader(file);
            int size=(int) file.length();
            char [] data=new char[size];
            int chars_read=0;
            while(chars_read<size)
                chars_read += in.read(data, chars_read, size-chars_read);
            txtDisplay.setText(new String(data));
        }catch(Exception ie){
            txtDisplay.setText(ie.getClass().getName() + ": " +ie.getMessage());
        }
        finally{try{if (in!=null)in.close();}catch(IOException eee){}}
        this.repaint();
    }
打算用swing中的JFileChooser来读取文件的,但是找到文件后总是显示java.io.FileNotFoundException: C:\Documents and Settings\Administrator\桌面 (拒绝访问。)   (再别的路径也一样)  网上说是路径必须是 “\\” 才可以,但是我不知道怎么弄,希望大家看看!
谢谢!!!

解决方案 »

  1.   

    你不能对文件夹进行读写
    只有文件才可以读写操作
    file=new File(fcSelect.getSelectedFile().getParent());//这个应该是得到选择文件的目录(文件夹)
                in=new FileReader(file);//不能对其进行读写
                int size=(int) file.length(); 
      

  2.   

    谢谢,已经解决!代码如下:
     file=new File(fcSelect.getSelectedFile().getString); //获得文件路径 
                in=new FileReader(file);   //创建字符流对文件进行读取
                int size=(int) file.length();    //检测文件大小
                char [] data=new char[size];     //以分配空间
                in.read(data, 0, size-0);    //读取字符 
                txtDisplay.setText(new String(data));    // 在文本区域中显示字符