1

是否有类似 Apache Commons IO for .Net 的库?

我正在寻找以下功能:

  • IOUtils.toByteArray(Stream);
  • IOUtils.toString(Stream);
  • FileUtils.write*();
  • 目录行者。
4

2 回答 2

2

像这样的功能是 .net 的一部分。不需要专门的图书馆。

示例: http ://www.xefteri.com/articles/show.cfm?id= 8 http://aspnet.4guysfromrolla.com/articles/072303-1.aspx

于 2009-07-21T13:15:36.807 回答
0

没有直接端口,AFAIK,但 Apache Commons IO 包含一大堆东西:

  • 实用程序类 - 使用静态方法来执行常见任务
  • 过滤器 - 文件过滤器的各种实现
  • java.util.Comparator比较器 - for 文件的各种实现
  • Streams - 有用的流、读取器和写入器实现

你是在追求特定的东西吗?

更新:对于例如 IOUtils.toByteArray(Stream) 的功能,您可以使用等效的

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

当然,要从字节数组中获取字符串,您只需使用适当的编码对其进行解码:

String s = encoding.GetString(bytes)

其中 encoding 是一个System.Text.Encoding实例,例如System.Text.UTF8Encoding. 我不确定是否有任何库提供您描述的其他功能,但它们很容易使用TextWriter.WriteLine、和编写BinaryWriter.Write,如本例所示Directory.GetDirectoriesDirectory.GetFiles

于 2009-07-21T13:16:12.110 回答