檔案讀寫操作

  • 原則上避免直接操作 Java File,所以提供 FileReadFacade/FileWriteFacade 以取得相關 Stream / Reader / Writer 等串流物件操作。
    • 都是使用 Buffered 實作回傳。
  • 資料量不大的時候,也可以直接寫入/讀取內容。
    • 內部原則上使用 IOUtils 處理。
  • 於 Srping 環境注入即可使用。

FileReadFacade


// BufferedReader / BufferedInputStream
createReader(LogicalFile)
createReader(LogicalFile, String charsetName)
createStream(LogicalFile)

// 直接讀檔
readByteArray(LogicalFile)
readByteArray(LogicalFile, long)
readLines(LogicalFile)
readLines(LogicalFile, String)
readString(LogicalFile)
readString(LogicalFile, String)

FileWriteFacade


// BufferedWriter / BufferedOutputStream
createStream(LogicalFile, boolean append)
createWriter(LogicalFile)
createWriter(LogicalFile, boolean append)
createWriter(LogicalFile, String charsetName)
createWriter(LogicalFile, String charsetName, boolean append)

// 直接寫檔
writeByteArray(LogicalFile, byte[])
writeByteArray(LogicalFile, byte[], boolean append)
writeString(LogicalFile, String)
writeString(LogicalFile, String, boolean append)
writeString(LogicalFile, String, String)
writeString(LogicalFile, String, String, boolean append)

results matching ""

    No results matching ""