我的目標是從文件中使用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