Topic: 各位大哥帮忙!(找不到指定文件)

  Print this page

1.各位大哥帮忙!(找不到指定文件) Copy to clipboard
Posted by: whhxtt
Posted on: 2006-03-28 14:32


import java.io.*;
public class FileDemo1 {

public static void main(String[] args)throws Exception {
int size;
InputStream f=new FileInputStream("FileDemo1.java");
System.out.println("Total Aviable Bytes:"+(size=f.available()));
int n=size/40;
System.out.println("First"+n+"bytes of file one read() at a time");
for(int i=0;i<n;i++){
System.out.println(f.read());
}
System.out.println("\nStill Avaible:"+f.available());
System.out.println("Reading the next"+n+"with one read()");
byte b[]=new byte[n];
if(f.read(b)!=n){
System.err.println("couldn't read"+n+"bytes");
}
System.out.println(new String(b,0,n));
System.out.println("nStill Avaible:"+(size=f.available()));
System.out.println("Skipping half of remaining bytes with skip()");
f.skip(size/2);
System.out.println("Still Avaible:"+f.available());
System.out.println("Reading"+n/2+"into the end of array");
if(f.read(b,0,n/2)!=n/2){
System.out.println("couldn't read"+n/2+"bytes");
}
System.out.println(new String(b,0,n/2));
System.out.println("\nStill Avaible:"+f.available());
f.close();
}

}

这个程序为什么运行时系统提示找不到指定文件啊?

2.Re:各位大哥帮忙! [Re: whhxtt] Copy to clipboard
Posted by: cargo
Posted on: 2006-03-28 15:03

那俩表情图片是什么源码?

3.Re:各位大哥帮忙! [Re: whhxtt] Copy to clipboard
Posted by: JavaandC
Posted on: 2006-03-28 15:11

你這個程序是怎麽運行的?我編譯運行都沒有問題。

4.Re:各位大哥帮忙!(找不到指定文件) [Re: whhxtt] Copy to clipboard
Posted by: whhxtt
Posted on: 2006-03-30 09:04

我用Eclipse3.01运行的啊。它提示这样的错误:java.io.FileNotFoundException: FileDemo1.java (系统找不到指定的文件。)
  at java.io.FileInputStream.open(Native Method)
  at java.io.FileInputStream.<init>(Unknown Source)
  at java.io.FileInputStream.<init>(Unknown Source)
  at FileDemo1.main(FileDemo1.java:19)
Exception in thread "main"

这是怎么一回事呢?小弟初学,很困惑。

5.Re:各位大哥帮忙! [Re: cargo] Copy to clipboard
Posted by: whhxtt
Posted on: 2006-03-30 09:06

cargo wrote:
那俩表情图片是什么源码?

这位仁兄的意思我不明白啊。。。。。

6.Re:各位大哥帮忙!(找不到指定文件) [Re: whhxtt] Copy to clipboard
Posted by: zcjl
Posted on: 2006-03-30 09:15

whhxtt wrote:
我用Eclipse3.01运行的啊。它提示这样的错误:java.io.FileNotFoundException: FileDemo1.java (系统找不到指定的文件。)
  at java.io.FileInputStream.open(Native Method)
  at java.io.FileInputStream.<init>(Unknown Source)
  at java.io.FileInputStream.<init>(Unknown Source)
  at FileDemo1.main(FileDemo1.java:19)
Exception in thread "main"

这是怎么一回事呢?小弟初学,很困惑。

你的java代码是不是放在类似src的目录下?用eclipse运行,默认的当前路径是项目的根目录

7.Re:各位大哥帮忙!(找不到指定文件) [Re: whhxtt] Copy to clipboard
Posted by: whhxtt
Posted on: 2006-03-30 09:44

对啊,那要怎样才可以呢?我对路径是一头雾水,一点都不懂。还有我这个程序也提示错误,就是我的路径写的有问题,错误是这样的:java.lang.Error: 无法解析的编译问题:
  转义序列无效(有效的转义序列为 \b \t \n \f \r \" \' \\)

  at xinhua.net.com.SequenceIuputStreamDemo.main(SequenceIuputStreamDemo.java:38)
Exception in thread "main"

程序如下:
package xinhua.net.com;

/**
* @author Administrator
*
* TODO 要更改此生成的类型注释的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
import java.io.*;
import java.util.*;
class InputStreamEnumerator implements Enumeration{
private Enumeration files;
public InputStreamEnumerator(Vector files){
this.files=files.elements();
}
public boolean hasMoreElements(){
return files.hasMoreElements();
}
public Object nextElement(){
try{
return new FileInputStream(files.nextElement().toString());
}
catch(Exception e){
return null;
}
}
}
public class SequenceIuputStreamDemo {
public static void main(String[]args)throws Exception{
int c;
Vector files=new Vector();
files.addElement("D:\Downloads\eclipse\workspace\jsp\file1.txt");
files.addElement("D:\Downloads\eclipse\workspace\jsp\file2.txt");
InputStreamEnumerator w=new InputStreamEnumerator(files);
InputStream input=new SequenceInputStreamWilted Rose;
while((c=input.read())!=-1){
System.out.println((char)c);
}
input.close();
}


}

8.Re:各位大哥帮忙!(找不到指定文件) [Re: whhxtt] Copy to clipboard
Posted by: whhxtt
Posted on: 2006-03-30 09:47

哪位大哥能给我讲解一下关于路径的知识啊?小弟感激不尽!!!

9.Re:各位大哥帮忙!(找不到指定文件) [Re: whhxtt] Copy to clipboard
Posted by: hoden_w
Posted on: 2006-03-30 17:38

我运行也是好的啊,怎么到你哪里就不好啊 下面是结果!

Total Aviable Bytes:1553
First 38 bytes of file one read() at a time
47
42
13
10
32
42
32
67
114
101
97
116
101
100
32
111
110
32
77
97
114
32
51
48
44
32
50
48
48
54
13
10
32
42
13
10
32
42

Still Avaible:1515
Reading the next38with one read()
TODO To change the template for this
nStill Avaible:1477
Skipping half of remaining bytes with skip()
Still Avaible:739
Reading19into the end of array
;
    System.out.pri

Still Avaible:720


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923