以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 Java/Eclipse 』  (http://bbs.xml.org.cn/list.asp?boardid=41)
----  找个能人帮忙解决一些这个问题,谢谢  (http://bbs.xml.org.cn/dispbbs.asp?boardid=41&rootid=&id=44160)


--  作者:leehiangger
--  发布时间:3/20/2007 8:49:00 PM

--  找个能人帮忙解决一些这个问题,谢谢
这是一段代码,可是在运行的时候老是提示又这个问题:xception in thread "main" java.io.FileNotFoundException: C:\Documents and Settings (拒绝访问。)
 at java.io.FileInputStream.open(Native Method)
 at java.io.FileInputStream.<init>(Unknown Source)
 at stream.FileInputStreamDemo.main(FileInputStreamDemo.java:9)
实在不明白是怎么回事了,难道是我输入流的读数据函数写错了么,初学,不明白,那位帮忙说说,谢谢先!
package stream;
import java.io.*;

public class FileInputStreamDemo {
 public static void main(String args[])throws IOException{
  String dir="C:/Documents and Settings";
  File file=new File(dir);
  if(file.exists()){
   FileInputStream f=new FileInputStream(file);
   DataInputStream in = new DataInputStream(f
     );
   int fsize=f.available();
   System.out.println("Total available bytes:"+fsize);
   int n=fsize/40;
   System.out.println("Reading first "+n+" bytes one at a time");
   for(int i=0;i<n;i++){
    System.out.println((char)f.read());
   }
   int temp=f.available()-n;
   System.out.println("\nstill available:"+temp);
   System.out.println("reading rhe next "+n+" bytes");
   byte []b=new byte[n];
   if(in.read(b)!=n){
    System.err.println("can't read"+n+"bytes");
   }
   System.out.println(new String(b,0,n));
   fsize=f.available();
   System.out.println("\nstill available:"+fsize);
   System.out.println("skiping half of remaining bytes");
   f.skip(fsize/2);
   System.out.println("\nstill available:"+fsize);
   System.out.println("reading  "+n/2+" into the end of array");
   if(in.read(b,n/2,n/2)!=n/2){
    System.err.println("couldn't read"+n/2+"bytes");
   }
   System.out.println(new String(b,0,b.length));
   System.out.println("\nstill available:"+f.available());
  }else{
   System.out.println("Directory "+dir+" is not exist!");
  }
  
 }
}
 


--  作者:菜籽
--  发布时间:3/31/2007 5:51:00 PM

--  
xception in thread "main" java.io.FileNotFoundException: C:\Documents and Settings (拒绝访问)
更改一下
C:\Documents and Settings 的权限
或者文件放在别的目录
--  作者:wangxu85910
--  发布时间:5/20/2007 11:20:00 PM

--  
="C:/Documents and Settings";这样写是不对地
应该写成这样:
="c:\\Documents and Settings"
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms