如何將InputStreamReader
轉換爲InputStream
?我有一個InputStream
其中包含一些字符串和字節數據,我想解析它。所以我把我的InputStream
換成BufferedReader
。然後我讀了3行。之後,我想按原樣獲取其餘數據(字節)。但是如果我試圖得到它沒有任何反應。 代碼片段:將InputStreamReader轉換爲InputStream
BufferedReader br = new BufferedReader(new InputStreamReader(is,"UTF-8"));
String endOfData = br.readLine();
String contentDisposition = br.readLine();
String contentType = br.readLine();
file = new File(filename);
if(file.exists()) file.delete();
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
byte[] data = new byte[8192];
int len = 0;
while (-1 != (len = is.read(data)))
{
fos.write(data, 0, len);
Log.e("len", len+"");
}
fos.flush();
fos.close();
is.close();
該文件是空的。如果我不包裝InputStream
它工作正常,但我需要讀取3行並將其刪除。 謝謝。