日期:2014-05-20  浏览次数:20892 次

InputStream为何是空指针
这段代码为什么inputstream的对象is是空指针???因为文件内没有内容 ?

    try {
        FileOutputStream fos = new FileOutputStream("C:\\Documents and Settings\\Administrator\\1" );
        InputStream is = test.class.getClassLoader().getResourceAsStream("1");
        //t.copyAll(is, fos);
        fos.close();
        is.close();
      } catch (Exception f) {
        //try to load anyways - could be a sharing violation
      }

------解决方案--------------------
LZ想得到的效果是什么
------解决方案--------------------
那个"1"目录有问题吧....
------解决方案--------------------
getResourceAsStream默认从环境变量的classpath中查找,未找到文件名为“1”的文件。
------解决方案--------------------
没有找到文件而不是文件中没有内容
------解决方案--------------------
文件中没有内容是不会为null的,应该是没找到对应的文件