檔案流和轉換流亂碼

2021-07-30 17:29:25 字數 930 閱讀 1110

實際開發中經常會遇到文字類檔案的讀寫或者是檔案複製傳輸等等

如果這個時候搞不清楚使用什麼樣的流就會亂碼,複製後的檔案打不開

要用什麼流由你的檔案的儲存結構(字元檔案還包括編碼集)和用途決定

* 使用緩衝和位元組陣列的位元組流複製檔案

*/public void copyfile(string sourcefilepath, string destinationfilepath)

} catch (filenotfoundexception e) catch (ioexception e) finally }

/* * 關閉流

*/public void close(closeable...c) catch (ioexception e)

} }

public filereader(file file) throws filenotfoundexception 

/**

*我們再跳到super裡去看

* creates an inputstreamreader that uses the default charset.

* 建立乙個使用預設字符集的inputstreamreader

* @param in an inputstream

*/

public inputstreamreader(inputstream in) catch (unsupportedencodingexception e)

}

物件流 列印流和轉換流

物件流 物件流 object0utputstream 0bjectinputstream 增強了緩衝區功能 增強了讀寫8種基本資料型別和字串功能 增強了讀寫物件的功能 1.read0bject 從流中讀取乙個物件 2.write0bject 0bject obj 向流中寫入乙個物件 使用流傳輸物件的...

轉換流 緩衝流

輸入 輸出流體系中提供了兩個轉換流,這兩個轉換流用於實現將位元組流轉換為字元流。1.1outputstreamwriter outputstreamwriter 是字元流通向位元組流的橋梁 可使用指定的字元編碼表,將要寫入流中的字元編碼成位元組。它的作用的就是,將字串按照指定的編碼表轉成位元組,在使...

IO流之轉換流

查閱outputstreamwriter的api介紹,outputstreamwriter 是字元流通向位元組流的橋梁 可使用指定的字元編碼表,將要寫入流中的字元編碼成位元組。它的作用的就是,將字串按照指定的編碼表轉成位元組,在使用位元組流將這些位元組寫出去。public static void w...