package javaee;import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;public class Testdayont {
private File file;
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public void foo(File file) throws IOException{
FileInputStream fis= new FileInputStream(file);
int b;
while((b=fis.read())!=-1){
if (file.isFile()){
File[] sd=file.listFiles();
System.out.println(sd);
}
else{
File[] sk= file.listFiles();
System.out.println(sk);
}
}
}
public Testdayont() {
super();
}
public Testdayont(File file) {
super();
this.file = file;
}
public static void main(String[] args) throws IOException {
File file=new File("E:/Program Files");
Testdayont sw= new Testdayont();
sw.setFile(file);
sw.foo(file);
}}
import java.io.FileInputStream;
import java.io.IOException;public class Testdayont {
private File file;
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public void foo(File file) throws IOException{
FileInputStream fis= new FileInputStream(file);
int b;
while((b=fis.read())!=-1){
if (file.isFile()){
File[] sd=file.listFiles();
System.out.println(sd);
}
else{
File[] sk= file.listFiles();
System.out.println(sk);
}
}
}
public Testdayont() {
super();
}
public Testdayont(File file) {
super();
this.file = file;
}
public static void main(String[] args) throws IOException {
File file=new File("E:/Program Files");
Testdayont sw= new Testdayont();
sw.setFile(file);
sw.foo(file);
}}
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileReader.<init>(FileReader.java:55)
at javaee.Testdayont.foo(Testdayont.java:17)
at javaee.Testdayont.main(Testdayont.java:45)
运行出来的就是这个结果
楼主想干什么?
如果楼主只是想输出E:\Program Files下文件的话public void foo(File file) throws IOException {
if (!file.isFile()) {
File[] sd = file.listFiles();
System.out.println(Arrays.toString(sd));
}
}