2009-07-21 123 views
1

是否有像Apache Commons IO for .Net一樣的庫?Apache Commons IO in .Net

我要尋找以下功能:

  • IOUtils.toByteArray(流);
  • IOUtils.toString(Stream);
  • FileUtils.write *();
  • DirectoryWalker。
+0

我已經更新了答案;-) – 2009-07-21 14:08:17

回答

0

這裏沒有一個直接的端口,據我所知,但是Apache下議院IO包括一大堆東西:

  • 實用工具類 - 靜態方法來執行常見任務
  • 篩選器 - 文件篩選器的各種實現
  • 比較器 - 針對fi的java.util.Comparator的各種實現萊
  • 流 - 有用流,讀寫器實現

你一些具體的事情後?

更新:例如, IOUtils.toByteArray(流)的功能,你可以使用等效

Stream stream; 
byte[] bytes; 
using (BinaryReader br = new BinaryReader(stream)) { 
     bytes = br.ReadBytes(stream.Length); 
} 

,當然,要獲得從字節數組的字符串,你只需要使用適當的編碼進行解碼:

String s = encoding.GetString(bytes) 

其中編碼是System.Text.Encoding實例,例如System.Text.UTF8Encoding。我不確定任何提供您描述的其他功能的庫,但它們易於使用TextWriter.WriteLineBinaryWriter.WriteDirectory.GetDirectoriesDirectory.GetFiles,如this example中所述。

+0

Yeap,toByteArray(Stream),toString(Stream)from(IOUtils)和write * from FileUtils。 – 2009-07-21 13:31:11

相關問題