這是我的測試程序。我需要它適用於某個地方。這可能很小,對此抱歉。但我仍然是首發。所以請幫助我。在java中使用InputStream和OutputStream傳輸時不顯示圖像
try{
File file1 = new File("c:\\Users\\prasad\\Desktop\\bugatti.jpg");
File file2 = new File("c:\\Users\\prasad\\Desktop\\hello.jpg");
file2.createNewFile();
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file1)));
String data = null;
StringBuilder imageBuild = new StringBuilder();
while((data = reader.readLine())!=null){
imageBuild.append(data);
}
reader.close();
BufferedWriter writer = new BufferedWriter(new PrintWriter(new FileOutputStream(file2)));
writer.write(imageBuild.toString());
writer.close();
}catch(IOException e){
e.printStackTrace();
}
嗯,你爲什麼要做'data = reader.readLine()'?用'jpg'文件..?我很肯定你需要使用這個'byte []'這個 – 3kings
你需要在這裏使用BufferedImage和ImageIO來滿足你的需求。請檢查此鏈接:https://www.dyclassroom.com/image-processing-project/how-to-read-and-write-image-file-in-java –
Javadocs的第一行指出「從文本中讀取文本一個字符輸入流,' –