How to save file from one folder to another?

0

I have a listView that displays the files from an external folder (usb). I want to select one of these files and save them to an internal folder (Basket).

Here's when I select an item from my listView , I get the position of the item, however from here, I do not know how to save this item in the internal folder. Thanks for any help right away.

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int posicao, long l) {
                valor = (String) listView.getItemAtPosition(posicao);
                File arquivo = (File) listView.getItemAtPosition(posicao);
    
asked by anonymous 02.08.2018 / 22:11

1 answer

0

I understand that you can already get the source file. The next step is to only make one copy of the source file.

Use the function below by passing the source and destination files as parameters;

public static void copy(File src, File dst) throws IOException {
try (InputStream in = new FileInputStream(src)) {
    try (OutputStream out = new FileOutputStream(dst)) {
        // Transfer bytes from in to out
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
    }
}
}

You can see more here .

    
02.08.2018 / 22:58