我的目标是从文件中使用BufferedReader从字节中获取字符串,但我可以获取字符串,但有些时候结果是'带字节的字符串',因此文件被损坏。 我用readline得到第一行,但它工作,但有一段时间字符串来的字节。 下面是代码我试图做到这一点从字节获取第一行字符与出字节
public static void main(String[] args) throws IOException {
InputStream inStream = null;
OutputStream outStream = null;
String line;
BufferedReader reader;
File afile = new File(
"snake2.jpg");
File bfile = new File(
"snake.jpg");
File file=new File("E://snake.txt");
// for stream reading and writing.....
inStream = new FileInputStream(afile);
outStream = new FileOutputStream(bfile);
OutputStream txt=new FileOutputStream(file);
// create byte array.....
ByteArrayOutputStream f = new ByteArrayOutputStream();
reader = new BufferedReader(new InputStreamReader(inStream));
line = reader.readLine();
去低级别'read'和测试逐字节查看是否有字符。 – 2014-08-28 07:07:50
@ScaryWombat你能告诉我一个例子吗? – 2014-08-28 07:08:45
可能是您的文件包含字符 – SparkOn 2014-08-28 07:11:16