Thanks!
JJ
I've got some random jsdoc at http://mook.moz.googlepages.com/File.html
but I'm not sure if it's all correct.
Be aware that if you do this for, say, a build of Firefox, then every
page would also have access to this :)
...This, of course, still is no tutorial.
http://developer.mozilla.org/en/docs/Introduction_to_the_JavaScript_shell
might help though...
--
Mook
mook dot moz plus stuff at gmail dot more stuff
Mook ha escrito:
> If you build SpiderMonkey yourself, you can get a mostly-working but
> sorta broken File global constructor/object thing if you build with
> JS_HAS_FILE_OBJECT (which also requires NSPR).
>
I have the Ubuntu build, probably from ultraverse (or suchlike). What
do you mean by mostly-working but sorta broken? And how do I find out
if that's been the case with the build? string /usr/bin/smjs?
> I've got some random jsdoc at http://mook.moz.googlepages.com/File.html
> but I'm not sure if it's all correct.
There's a broken link, but I gather from it that there must be a
File.js file lying somewhere; it's not included with the smjs packet.
Any idea?
> Be aware that if you do this for, say, a build of Firefox, then every
> page would also have access to this :)
My intention is to use JS stand-alone, mostly.
Thanks for the answers!
JJ
var f1 = new java.io.File("/home/bob/file1.txt");
var f2 = new java.io.File("/home/bob/file2.txt");
f1.renameTo(f2);
Additionally, you can assign often-used class objects to shorter-named
variables:
var File = java.io.File;
var f1 = new File("/home/bob/file1.txt");
var f2 = new File("/home/bob/file2.txt");
f1.renameTo(f2);
You should be able to read write files too:
var w = new java.io.FileWriter("/home/bob/hello.txt");
try
{
w.write("Hello world\n");
}
finally
{
w.close();
}
etc.
Of course, this pretty much ties your JavaScript code to Rhino.
Attila.
> _______________________________________________
> dev-tech-js-engine mailing list
> dev-tech-...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-js-engine
>
--
home: http://www.szegedi.org
weblog: http://constc.blogspot.com
Visit Szegedi Butterfly fractals at:
http://www.szegedi.org/fractals/butterfly/index.html
> ECMAScript doesn't specify any standardized I/O library. In Rhino, you can
> use java.io.* classes directly, i.e. you can do stuff like
>
> var f1 = new java.io.File("/home/bob/file1.txt");
> var f2 = new java.io.File("/home/bob/file2.txt");
> f1.renameTo(f2);
>
> Additionally, you can assign often-used class objects to shorter-named
> variables:
>
> var File = java.io.File;
> var f1 = new File("/home/bob/file1.txt");
> var f2 = new File("/home/bob/file2.txt");
> f1.renameTo(f2);
>
> You should be able to read write files too:
>
> var w = new java.io.FileWriter("/home/bob/hello.txt");
> try
> {
> w.write("Hello world\n");
> }
> finally
> {
> w.close();
> }
Thanks a lot, it seems to work!
JJ
You might try a 3rd party SpiderMonkey shell. These work on Linux and
Windows, and there are probably others. Maybe somebody could add some
links to http://www.mozilla.org/js/projects.html.
JSDB: www.jsdb.org
wxJS: http://users.skynet.be/saw/wxJS/
Shanti
var file_name = arguments[0];
var f = new FileReader(file_name);
var br = new BufferedReader( f );
var resultados= new Array;
var line = new String;
while ((line = br.readLine()) != null) {
var estaLinea = new String( line );
var resultado = estaLinea.split(" ");
switch (resultado[2]) {
case '1':
if ( resultados[resultado[0]] ) {
resultados[resultado[0]]+=3;
} else {
resultados[resultado[0]]=3;
}
break;
case 'x':
if ( resultados[resultado[0]] ) {
resultados[resultado[0]]+=1;
} else {
resultados[resultado[0]]=1;
}
if ( resultados[resultado[1]] ) {
resultados[resultado[1]]+=1;
} else {
resultados[resultado[1]]=1;
}
break;
default:
if ( resultados[resultado[1]] ) {
resultados[resultado[1]]+=3;
} else {
resultados[resultado[1]]=3;
}
break
}
}
for ( var i in resultados ) {
print( i + ": " + resultados[i])
}
--
It's a bit complicated, but I guess reading files in Java is. The
tricky part was figuring out that Strings in Java are _not_ Strings in
JS, but it's a straightforward conversion.
JJ
Soubok
On Jan 3, 6:45 am, sha...@shantirao.com wrote:
> Hi JJ,
>
> You might try a 3rd party SpiderMonkey shell. These work on Linux and
> Windows, and there are probably others. Maybe somebody could add some
> links tohttp://www.mozilla.org/js/projects.html.