import java.io.*;
public class Test
{ public static void main(String args[])
{
try {
byte buf[] = new byte[50];
System.in.read(buf);
String s1=new String(buf);
s1 = s1.trim(); -----------------更改之处
System.out.println(buf);
System.out.println(s1);
File file=new File(s1);
System.out.println("File existed?"+file.exists());
System.out.println("Is File? "+file.isFile());
System.out.println("IS Dir? "+file.isDirectory());
System.out.println("File Name: "+file.getName());
System.out.println("File Dir: "+file.getPath());
System.out.println("Can read? "+file.canRead());
System.out.println("Can write? "+file.canWrite()); }catch(IOException e){
System.out.println(e.toString());
}
}
}
你读进来的文件名后边犹太多的空格了,去掉了就应该能找到文件了,我已经运行通过了,你可以试试!
public class Test
{ public static void main(String args[])
{
try {
byte buf[] = new byte[50];
System.in.read(buf);
String s1=new String(buf);
s1 = s1.trim(); -----------------更改之处
System.out.println(buf);
System.out.println(s1);
File file=new File(s1);
System.out.println("File existed?"+file.exists());
System.out.println("Is File? "+file.isFile());
System.out.println("IS Dir? "+file.isDirectory());
System.out.println("File Name: "+file.getName());
System.out.println("File Dir: "+file.getPath());
System.out.println("Can read? "+file.canRead());
System.out.println("Can write? "+file.canWrite()); }catch(IOException e){
System.out.println(e.toString());
}
}
}
你读进来的文件名后边犹太多的空格了,去掉了就应该能找到文件了,我已经运行通过了,你可以试试!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货