4 ms·
This is why I love .Net. Want a quick and dirty file read? string fileContent = System.IO.File.ReadAllText(); Want to read it into lines? string[] fileLines =
by TeHCrAzY 17y ago
This is why I love .Net. Want a quick and dirty file read?
string fileContent = System.IO.File.ReadAllText();
Want to read it into lines?
string[] fileLines = System.IO.File.ReadAllLines();
Want fine tuned byte by byte access?
var fs = new System.IO.FileStream(path);
They certainly looked long and hard at Java before writing .net, and covered many of the sore points carefully.
- cubicle67 17y agoI think you've missed specifying the filename, but otherwise cool. Here's Ruby for comparison: file_content = IO.read(filename) file_lines = IO.read(filename).split("\n")
- deleted 17y ago[deleted]
- regularfry 17y agofile_lines = File.readlines(filename) Not that it matters hugely :-)
- mmastrac 17y agoNot all of those methods were in .Net 1.0. I worked through the painful years of .Net 0.9 to .Net 2.0 and it wasn't always roses. The core libraries were really terrible and sparse in the early versions. Microsoft was a lot more aggressive in how they extended the core libraries post-2.0. There was an amazing amount of baggage in the language by the time 2.0 came out. FWIW, you can do the first two items you mention using the Apache Commons IOUtils class in Java. The latter is part of Java: http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileInputStream.html http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileInputStr...