0
我有一個構造函數如下:如何將文件內容轉換爲字符串?
MyClassName(File f) throws Exception;
和TXT文件看起來是這樣的:
. . . . .
. . . . .
. x . . .
. x x . .
. . . . .
. . . . .
當打開該文件,我怎麼把它轉換爲字符串?
像這樣:
". . . . .\n
. . . . .\n
. x . . .\n
. x x . .\n
. . . . .\n
. . . . .\n"
目前還不清楚你的意思 - 這有點聽起來像你想創建一個字符串文字,但是你不能有多行字符串文字(不是沒有明確地連接這些行,反正)。 –
'新的字符串(Files.readAllBytes(f.toPath()))' –
@ElliottFrisch值得一提這裏的文件編碼 - 平臺默認可能不正確。雖然它的內容不應該有太大的影響。 –