[Mono-dev] Read file under Linux?
monoman at gmail.com
Wed Aug 25 12:24:58 EDT 2010
Besides what Alex said you need a way to find the file.
You may try to use Assembly.Codebase with Assembly.GetEntryAssembly()
to first locate where your executable is, then use
System.Io.Path.Combine() to compose the full path to your properties
Rafael "Monoman" Teixeira
"We live in a world operated by science and technology. We have also
arranged things so that almost no one understands science and
technology. This is a prescription for disaster. We might get away
with it for a while, but sooner or later this combustible mixture of
ignorance and power is going to blow up in our faces."
On Thu, Aug 5, 2010 at 2:39 PM, SamHellawell <samlikeswilly at live.co.uk> wrote:
> Hey there!
> Basically, my C# project works perfectly well under Windows, and after
> sorting out some GAC problems it *almost* works on Linux. I am stump however
> as to how to open and read a file under Linux using Mono, i have tried
> entering Linux paths and local paths. The file I wish to read is within the
> same directly as the binary. If anybody could help me out, i'd greatly
> appreciate it. The file i wish to load is called example.properties
> My load function:
> public Boolean Load(string filename)
> FileStream file = File.Open(filename, FileMode.Open);
> UTF8Encoding temp = new UTF8Encoding(true);
> string fileContents = "";
> byte b = new byte;
> while (file.Read(b, 0, b.Length) > 0)
> fileContents += temp.GetString(b);
> string lineSplit = fileContents.Split((char)10);
> for(int i = 0; i < lineSplit.Length; i++)
> return true;
> Console.WriteLine("Unable to load properties file: " +
> return false;
> Cheers, Sam.
> View this message in context: http://mono.1490590.n4.nabble.com/Read-file-under-Linux-tp2315366p2315366.html
> Sent from the Mono - Dev mailing list archive at Nabble.com.
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
More information about the Mono-devel-list