David Reis
David Reis

Reputation: 365

Apache Commons IO in .Net

Is there a library like Apache Commons IO for .Net?

I am looking for the following functions:

Upvotes: 1

Views: 1018

Answers (2)

Vinay Sajip
Vinay Sajip

Reputation: 99465

There's not a direct port, AFAIK, but Apache Commons IO includes a whole bunch of stuff:

  • Utility classes - with static methods to perform common tasks
  • Filters - various implementations of file filters
  • Comparators - various implementations of java.util.Comparator for files
  • Streams - useful stream, reader and writer implementations

Are you after something specific?

Update: for e.g. the functionality of IOUtils.toByteArray(Stream) you can use the equivalent

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

and, of course, to get a string from the byte array, you simply need to decode it using the appropriate encoding:

String s = encoding.GetString(bytes)

where encoding is a System.Text.Encoding instance, for example System.Text.UTF8Encoding. I'm not sure of any libraries which provide the other functions you describe, but they're easy to write using TextWriter.WriteLine, BinaryWriter.Write, Directory.GetDirectories and Directory.GetFiles as in this example.

Upvotes: 0

b0x0rz
b0x0rz

Reputation: 3981

functionality like that is A PART of .net. no need for a special library.

examples: http://www.xefteri.com/articles/show.cfm?id=8 https://web.archive.org/web/20210518224206/http://aspnet.4guysfromrolla.com/articles/072303-1.aspx

Upvotes: 2

Related Questions