Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm using the code below to try and move my database file to my sdcard. I have no problems except that I get a redline under sd. Any ideas?

File data = Environment.getDataDirectory();
if (sd.canWrite()) {
    String currentDBPath = "\data\application.package\databases\name";
    String backupDBPath = "name";
    File currentDB = new File(data, currentDBPath);
    File backupDB = new File(sd, backupDBPath);
    if (currentDB.exists()) {
        FileChannel src;
    try {
    src = new FileInputStream(currentDB).getChannel();
        FileChannel dst = new FileOutputStream(backupDB).getChannel();
        try {
        dst.transferFrom(src, 0, src.size());
    src.close();
            dst.close();
        } catch (IOException e) {                                                    
            e.printStackTrace();
        }
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    }

enter image description here

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
135 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can only use a variable if you create an instance of it:

Put this before your code:

File sd = Environment.getExternalStorageDirectory();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...