您的位置:首页 > 编程语言 > Java开发

Java中的 File类对文件 路径分割符不敏感! <发现>

2012-10-10 19:54 429 查看
在Xml 中有时候定义 id 搞成了

   <TextView  android:text="@+id/mytext"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

写的虽然是错误的,但是 居然R.id.mytext存在!!调用时候会报空指针异常。

java创建文件和文件夹 的File类 ,对"/" 也即是File.separator 不敏感啊!我输入那么多分隔符居然只被当作一个"/"
import java.io.*;
public class Test {
	public static void main(String[]arg) {
		/* InputStreamReader isr = new InputStreamReader(new 
		FileInputStream(new File("C:\\Users\\joychine\\Desktop\\新建文本文档.txt")));
		byte [] temp = new byte[4*1024];
		int s = 0;
		if((s=read(temp))!=-1) 
			System.out.println(s); */
		File f = new File("D:/duomi"+File.separator+File.separator+File.separator+File.separator+"//////新建文件夹/新建文件夹2");//这句话居然能编译而且运行!
		File f1 = new File(f,"/t11xt.txt");
		System.out.println(f.getName());
		System.out.println(f1.getName());
		System.out.println(f.getPath());
		System.out.println(f1.getPath());
		try {
		
		f.mkdir();
		f1.createNewFile();
	} catch (Exception e){
		e.printStackTrace();
	}
	}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: