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\桌面 (拒绝访问。) (再别的路径也一样) 网上说是路径必须是 “\\” 才可以,但是我不知道怎么弄,希望大家看看!
谢谢!!!
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\桌面 (拒绝访问。) (再别的路径也一样) 网上说是路径必须是 “\\” 才可以,但是我不知道怎么弄,希望大家看看!
谢谢!!!
解决方案 »
- System.out.println(".g.dfg.g".replaceAll(".","@")); 结果为啥不对?
- hello world 程序(大急求助啊)
- 选项卡标签问题
- java Runtime类求助
- sitemesh定义多个装饰器问题
- 求求个位好心人啦!!谢谢谢谢帮帮忙我是菜鸟!
- 如何做个非方型的FRAME...
- 请问怎么设定让一个JTextArea只能输入200个字节,谢谢
- 如何设置一个 LookAndFeel 的 default 字体大小?
- 类似VC里信号量的功能在JAVA里如何实现?
- 我想做一个在(1--5)随机依次抽出号码的程序,可是遇到问题了。大家解决一下a[i]==a[j] 报错啊
- 大学专业发展方向?
只有文件才可以读写操作
file=new File(fcSelect.getSelectedFile().getParent());//这个应该是得到选择文件的目录(文件夹)
in=new FileReader(file);//不能对其进行读写
int size=(int) file.length();
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)); // 在文本区域中显示字符