2013-03-18 34 views
0

在foldleft,我試圖消化不同的圖像。我感到沮喪,並決定閱讀相同的文件,我收到不同的字節數組閱讀相同的文件!有誰知道爲什麼會發生這種情況?這裏是正在發生的代碼,「swap.png」從不運行閱讀相同的文件,但得到不同的字節

val capturedImage = outputScreen.capture 
    val swap = new File("swap1.png") 
    ImageIO.write(capturedImage, "png", swap) 
    val bis = new BufferedInputStream(new FileInputStream("swap.png")) 
    val byte = Stream.continually(bis.read).takeWhile(-1 !=).map(_.toByte).toArray 
    println(byte.toString) 

這期間改變的是一些輸出

[[email protected] 
[[email protected] 
[[email protected] 
[[email protected] 
[[email protected] 
[[email protected] 

回答

4

什麼你得到的是字節數組的代表性的toString (因爲[B),默認爲Object.toString()。 Object.toString是做什麼的?通常,它只是打印有關內存中對象的內部信息(所謂的identity hash)*。因此,在不同的運行中產生不同的輸出,在不同的RAM存儲器位置有不同的對象是完全正確的。嘗試,而不是在最後一行這樣的問題.mkString(",")

println(byte.mkString(",")) 

*但可能有不同的實現

+0

哇靠謝謝!我正在那頭拉我的頭髮。每天學些新東西 – dakillakan 2013-03-18 04:41:01

相關問題