文本文件中有一个字符串,其中包括'\n'作为换行标志,但是从文件中读出后,似乎系统不认为\n是一个字符,这个比较麻烦,因为我在扫描字符的时候使用string.charAt(index)== '\n'来判断是否遇到了换行标志而如果这个字符串hardcode在程序中就没有问题,完全可以用:string.charAt(index) == '\n'来判断。请问如何解决?因为这个字符是需要保存在文件中的。
调试欢乐多
我开始用的是RandomAccessFile,然后readline,读出的字符串如下:Director:Some man \n Actor:Some man ,Some woman\n This is the introduction of the movie,This is the introduction of the movie,This is the introduction of the movieThis is the introduction of the movieThis is the introduction of the movie,This is the introduction of the movieThis is the introduction 。然后在扫描的时候,其中的\n没有被当作一个char,而是一个string,我用了BufferedReader,结果是完全一样的。:-(
StringTokenizer Tmp = new StringTokenizer(string, "\r\n");记住是\r\n,不是\n
String a ="abc\\nad";
Pattern pa = Pattern.compile("\\\\n");
Matcher ma = pa.matcher(a);
while(ma.find()){
System.out.println(ma.group());
}
String lineSep = System.getProperty("line.separator")
\r \n \r\n
3个逐一判断一下把
设置一个缓冲 碰到\r再判断后面是否是\n