读书人

f.isDirectory() 字符串有关问题

发布时间: 2013-09-12 22:07:00 作者: rapoo

f.isDirectory() 字符串问题



为什么f.isDirectory()会是false?

f.isDirectory() : f是不是一个文件目录》

你的“F:/workspace/src"
目录存在么? 存在的话,应该会显示true的。

[解决办法]
你的程序我改了下 你看是不是想这么干

Scanner scanner=new Scanner(System.in);
String is=scanner.nextLine();
// int count = 0;
//// while (count == 0) {
//// count = is.available();
//// }
// byte[] b = new byte[count];
// is.read(b);
// String str = new String(b);
System.out.println(is);



File f = new File(is);
System.out.println(f.isDirectory());
}
false是因为你的str为空,所以f也为空,你路径无论怎么写,都是为false的
[解决办法]
输入后,你按了回车换行enter键吧,
字符串不对,多加了编码0x0d, 0x0a,
把字符串最后两个字符去掉看看

读书人网 >Eclipse开发

热点推荐