0

So.. I'm really frustrated. It's still happening. All I want to do is copy a folder, files inside it, it's child folders, files inside them and so on.. Sounds simple, right? Well, here's my code - please tell me what I'm doing wrong. I've tried everything, all methods, ended up with FileUtils which I find easiest..

Starting the startCopy:

try{startCopy();}catch (IOException e){Toast.makeText(getApplicationContext(), "Unknown Error", Toast.LENGTH_SHORT).show();}

and the startCopy itself:

public void startCopy() throws IOException{
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    String blitzWhere = prefs.getString("blitzWhere", null);
    Spinner SpinnerReplace=(Spinner) findViewById(R.id.SpinnerReplace);
    String toReplace = SpinnerReplace.getSelectedItem().toString();
    Spinner SpinnerReplaceWith=(Spinner) findViewById(R.id.SpinnerReplaceWith);
    String replacedBy = SpinnerReplaceWith.getSelectedItem().toString();
    File lowBackup = new File(blitzWhere + "/Android/data/net.wargaming.wot.blitz/files/Data/3d/Maps/hangarlow_b");
    File premiumBackup = new File(blitzWhere + "/Android/data/net.wargaming.wot.blitz/files/Data/3d/Maps/hangar_b");
    lowBackup.mkdirs();
    premiumBackup.mkdirs();
    if (!lowBackup.isDirectory() && !premiumBackup.isDirectory()){
        File hangarLow = new File(blitzWhere + "/Android/data/net.wargaming.wot.blitz/files/Data/3d/Maps/hangarlow");
        File hangar = new File(blitzWhere + "/Android/data/net.wargaming.wot.blitz/files/Data/3d/Maps/hangar");

        lowBackup.mkdirs();
        premiumBackup.mkdirs();
        FileUtils.copyDirectory(hangarLow, lowBackup);
        FileUtils.copyDirectory(hangar, premiumBackup);

    }

    Toast.makeText(getApplicationContext(), blitzWhere, Toast.LENGTH_LONG).show();
    Toast.makeText(getApplicationContext(), toReplace, Toast.LENGTH_LONG).show();
    Toast.makeText(getApplicationContext(), replacedBy, Toast.LENGTH_LONG).show();


    successfulCopy();
}

Everything it does is that it toasts the "Unknown Error" message, which is what I want if the IOException is thrown. I'm a Java newbie and I'm learning on-the-go. Of course, both folders (hangar_b and hangarlow_b) don't exist, otherwise the problem could be here. So, any ideas? Thanks.

PetrMolek
  • 23
  • 1
  • 4
  • Never consume an exception without logging it (e.g., using `Log.e()`). Replace your `Toast` to log the exception. Then, use LogCat to examine the Java stack trace: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Jun 13 '16 at 20:15
  • Well, I'll do it tomorrow. – PetrMolek Jun 13 '16 at 20:22

0 Answers0