I’m having trouble copying a file inside a script.

I’m having trouble copying a file inside a script. I’m deleting the current LL desktop wallpaper, and then trying to copy a new one in there for a wallpaper changer. I have Java code to copy the file, but I’m having trouble with the javascript translation. Perhaps there’s an easy way to copy files inside LL scripts?

]]>

9 Commentsto I’m having trouble copying a file inside a script.

  1. Anonymous says:

    < ![CDATA[

    There isn’t. LL isn’t meant to be a file manager 😉



    You’ll need two Streams connected for this.

    ]]>

  2. Anonymous says:

    < ![CDATA[

    Yeah, I figured.  I’m having to use a hack Pierre recommended since the LL wallpaper isn’t accessible via the API yet.  I guess I’ll just have to find a way to handle the Java primitives in javascript.

    ]]>

  3. Anonymous says:

    < ![CDATA[

    I confirm this, you need to use streams but this is not exactly obvious.


    The loop is quite easy, but you need to use a special syntax to allocate a byte buffer, something like this:


    var buffer = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024);


    Also don’t forget to close streams in a finally statement.

    ]]>

  4. Anonymous says:

    < ![CDATA[

    That’s the syntax I was looking for!  Although, I got it to work doing this:



    LL.bindClass(“java.io.File”);


    LL.bindClass(“java.io.FileOutputStream”);


    LL.bindClass(“java.io.FileInputStream”);



    var test = new File(“/storage/external_SD/Android/data/net.pierrox.lightning_launcher/files/test-1.txt”);


    var test2 = new File(“/storage/external_SD/Android/data/net.pierrox.lightning_launcher/files/blah.txt”);


    copy(test, test2);



    function copy(src, dst){


    var input = new FileInputStream(src);


    var out = new FileOutputStream(dst);


    var b = input.read();


    while(b != -1) 



    out.write(b); 


    b = input.read();



    input.close(); 


    out.close();


    ]]>

  5. Anonymous says:

    < ![CDATA[

    That works too!!! (although probably not very efficient, this may cause ANR issues).


    You may also need to do the work in another thread, I believe some Android versions will complain about IO on the UI thread.

    ]]>

  6. Anonymous says:

    < ![CDATA[

    Yeah.  I just wanted to get a POC working, and I was limited without being able to create a byte array.  I think I’m also going to look at a FileChannel operation.  It seems to abstract away some of the parts of the file transfer.  Thanks again!  (Making Java into javascript is hard work!)

    ]]>

  7. Anonymous says:

    < ![CDATA[

    Just a though: maybe java.lang.Runtime.exec with a command line like “cp /from/path /to/path” could do the trick.


    (but issues with characters to escape and so on)

    ]]>

  8. Anonymous says:

    < ![CDATA[

    That’s genius!  I always forget you can do that.  This works like a charm:



    LL.bindClass(“java.lang.Runtime”);



    var path1 = “/storage/external_SD/Android/data/net.pierrox.lightning_launcher/files/test-1.txt”


    var path2 = “/storage/external_SD/Android/data/net.pierrox.lightning_launcher/files/blah.txt”



    var rt = Runtime.getRuntime()


    rt.exec(“cp ” + path1 + ” ” + path2)

    ]]>

  9. Anonymous says:

    < ![CDATA[

    🙂

    ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *