[Neko] neko.io.File problem

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[Neko] neko.io.File problem

Viktor Hesselbom
Hello,

I have a problem with reading a text file when compiling to Neko.

I have this code:

import neko.io.File;
import neko.Lib;

class Main 
{
static function main () 
{
try
{
content = File.getContent ("test.txt");
}
catch (e : Dynamic)
{
trace (e);
}
}
static var content : String;
}

I have a try...catch because it was giving me an error and now it outputs: "[file_contents,test.txt]". test.txt is in the same folder as the outputted .n file. I've also tried with "./test.txt" instead of "test.txt". test.txt contains some random letters.

I'm not sure what this error means. I want to load the file and get the text in a string variable, how do I get this to work?

Thanks for any help,
Viktor

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [Neko] neko.io.File problem

Juan Delgado
I'm using this in HippoHX:

        var f:FileInput = neko.io.File.read(filePath,false);
        var content:String = f.readAll().toString();
               
        f.close();

You can check out a bunch of File related methods here:

http://hippohx.googlecode.com/svn/trunk/src/server/com/hippohx/File.hx

Not sure about your problem, I've never used File.getContent before.

Cheeres!

On Mon, Nov 17, 2008 at 2:01 PM, Viktor Hesselbom
<[hidden email]> wrote:

> Hello,
> I have a problem with reading a text file when compiling to Neko.
> I have this code:
> import neko.io.File;
> import neko.Lib;
> class Main
> {
> static function main ()
> {
> try
> {
> content = File.getContent ("test.txt");
> }
> catch (e : Dynamic)
> {
> trace (e);
> }
> }
> static var content : String;
> }
> I have a try...catch because it was giving me an error and now it outputs:
> "[file_contents,test.txt]". test.txt is in the same folder as the outputted
> .n file. I've also tried with "./test.txt" instead of "test.txt". test.txt
> contains some random letters.
> I'm not sure what this error means. I want to load the file and get the text
> in a string variable, how do I get this to work?
> Thanks for any help,
> Viktor
> --
> haXe - an open source web programming language
> http://haxe.org
>



--
Juan Delgado - Zárate
http://zarate.tv
http://dandolachapa.com
http://loqueyosede.com

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [Neko] neko.io.File problem

Zjnue Brzavi
In reply to this post by Viktor Hesselbom
Hi,

> I have a problem with reading a text file when compiling to Neko.
[..]
> content = File.getContent ("test.txt");

I believe you have to use an absolute path for getContent.

Try:
content = File.getContent (neko.Sys.getCwd()+"test.txt");

Zjnue

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [Neko] neko.io.File problem

Viktor Hesselbom
In reply to this post by Juan Delgado
Hello Juan,

Thanks for your help. The strange thing is that I get the same error on the neko.io.File.read row with this.

2008/11/17 Juan Delgado <[hidden email]>
I'm using this in HippoHX:

       var f:FileInput = neko.io.File.read(filePath,false);
       var content:String = f.readAll().toString();

       f.close();

You can check out a bunch of File related methods here:

http://hippohx.googlecode.com/svn/trunk/src/server/com/hippohx/File.hx

Not sure about your problem, I've never used File.getContent before.

Cheeres!

On Mon, Nov 17, 2008 at 2:01 PM, Viktor Hesselbom
<[hidden email]> wrote:
> Hello,
> I have a problem with reading a text file when compiling to Neko.
> I have this code:
> import neko.io.File;
> import neko.Lib;
> class Main
> {
> static function main ()
> {
> try
> {
> content = File.getContent ("test.txt");
> }
> catch (e : Dynamic)
> {
> trace (e);
> }
> }
> static var content : String;
> }
> I have a try...catch because it was giving me an error and now it outputs:
> "[file_contents,test.txt]". test.txt is in the same folder as the outputted
> .n file. I've also tried with "./test.txt" instead of "test.txt". test.txt
> contains some random letters.
> I'm not sure what this error means. I want to load the file and get the text
> in a string variable, how do I get this to work?
> Thanks for any help,
> Viktor
> --
> haXe - an open source web programming language
> http://haxe.org
>



--
Juan Delgado - Zárate
http://zarate.tv
http://dandolachapa.com
http://loqueyosede.com

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [Neko] neko.io.File problem

Viktor Hesselbom
In reply to this post by Zjnue Brzavi
Oh, I just got it.

I had the compile.bat and Main.hx files in a src/ folder and output in a /bin folder. I didn't cd ../bin before opening that outputted file so it would look in src/ for that file when it is in bin/. When I open the file after compiling from the correct folder it works.

Thanks for the help both of you.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [Neko] neko.io.File problem

Daniel Turing
In reply to this post by Viktor Hesselbom
On Mon, 2008-11-17 at 15:01 +0100, Viktor Hesselbom wrote:
> "[file_contents,test.txt]". test.txt is in the same folder as the
> outputted
> .n file

test.txt must be in your current working directory when you run your
program. It being in the same folder as the .n doesnt help.

File.getContent() works great for me.

-dan



--
haXe - an open source web programming language
http://haxe.org