首先我用eclipse写了一段代码,读文件信息的,是一个实例来得如下import java.io.*;
public class fileInfo {
File fileToCheck;
public static void main(String[] args) throws IOException {
if (args.length>0){
for (int i=0;i<args.length;i++){
File fileToCheck = new File(args[i]);
info(fileToCheck);
}
}
else {
System.out.println("Nofile given.");
}
}
public static void info(File f) throws IOException {
System.out.println("Name:"+f.getName());
System.out.println("Path:"+f.getAbsolutePath());
if (f.exists()){
System.out.println("File exists.");
System.out.println((f.canRead()?"and is Readable":""));
System.out.println(".");
System.out.println("File is "+f.length() + "bytes.");
}
else
System.out.println("File does not exist.");
}
}我并没有在eclipse里面run,而是用jdk的javac在dos下编译为class文件,但是出错了,错误如下
E:\workBuffer\java workspace>javac fileInfo.java
fileInfo.java:1: 'class' or 'interface' expected
锘縤mport java.io.*;
^
1 error
奇怪的就在eclipse里面是正常的到这就出现这个问题,谢谢
public class fileInfo {
File fileToCheck;
public static void main(String[] args) throws IOException {
if (args.length>0){
for (int i=0;i<args.length;i++){
File fileToCheck = new File(args[i]);
info(fileToCheck);
}
}
else {
System.out.println("Nofile given.");
}
}
public static void info(File f) throws IOException {
System.out.println("Name:"+f.getName());
System.out.println("Path:"+f.getAbsolutePath());
if (f.exists()){
System.out.println("File exists.");
System.out.println((f.canRead()?"and is Readable":""));
System.out.println(".");
System.out.println("File is "+f.length() + "bytes.");
}
else
System.out.println("File does not exist.");
}
}我并没有在eclipse里面run,而是用jdk的javac在dos下编译为class文件,但是出错了,错误如下
E:\workBuffer\java workspace>javac fileInfo.java
fileInfo.java:1: 'class' or 'interface' expected
锘縤mport java.io.*;
^
1 error
奇怪的就在eclipse里面是正常的到这就出现这个问题,谢谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货