我想从文件中读取字符串。当找到某个字符串(><
)时,我想要开始读取整数,并将它们转换为二进制字符串。从字符串文件中读取时如何识别特殊的分隔符字符串?
我的程序读取字符串,并将其保存在ArrayList
成功,但它 不承认><
符号,因此二进制字符串的读取不成功。
守则
try {
FileInputStream fstream = new FileInputStream(fc.getSelectedFile().getPath());
// Get the object of DataInputStream
DataInputStream ino = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(ino));
String ln;
String str, next;
int line, c =0;
while ((ln = br.readLine()) != null) {
character = ln;
System.out.println(character);
iname.add(ln); // arraylist that holds the strings
if (iname.get(c).equals("><")) {
break; // break and moves
// on with the following while loop to start reading binary strings instead.
}
c++;
}
String s = "";
// System.out.println("SEQUENCE of bytes");
while ((line = ino.read()) != -1) {
String temp = Integer.toString(line, 2);
arrayl.add(temp);
System.out.println("telise? oxii");
System.out.println(line);
}
ino.close();
} catch (Exception exc) { }
我试图读取该文件,例如:
T
E
a
v
X
L
A
.
x
"><"
sequence of bytes.
其中最后一部分被保存为字节,以及文本文件看起来像。不用担心这个位有效。所有的字符串都保存在一个新的行中。
“>”会自己排成一行吗?因为否则你写的是不行的。该行中是否还有其他字符(空格等)? – Christina 2011-03-18 15:29:41
你能举一个你想要阅读的格式的例子吗? – 2011-03-18 15:31:18
@Christina是“>”它本身就是一条线。没有别的是写在那一行。 – elena 2011-03-18 15:34:06