2
我正在使用ProgramAB与Android,它需要我通过在资产文件夹中创建/ bots /目录将aiml文件从资产文件夹复制到外部存储。这是我从this教程中获得的代码,教程讲述了android中的chatbots(这个代码中调用的其他函数与目录复制无关)。将资产文件夹子目录复制到外部存储中的特定文件夹
我已经尝试了其他解决方案,但没有为我工作。
//checking SD card availablility
boolean a = isSDCARDAvailable();
//receiving the assets from the app directory
AssetManager assets = getResources().getAssets();
File jayDir = new File(Environment.getExternalStorageDirectory().toString() + "/hari/bots/Hari");
boolean b = jayDir.mkdirs();
if (jayDir.exists()) {
//Reading the file
try {
for (String dir : assets.list("Hari")) {
File subdir = new File(jayDir.getPath() + "/" + dir);
boolean subdir_check = subdir.mkdirs();
for (String file : assets.list("Hari/" + dir)) {
File f = new File(jayDir.getPath() + "/" + dir + "/" + file);
if (f.exists()) {
continue;
}
InputStream in = null;
OutputStream out = null;
in = assets.open("Hari/" + dir + "/" + file);
out = new FileOutputStream(jayDir.getPath() + "/" + dir + "/" + file);
//copy file from assets to the mobile's SD card or any secondary memory
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
//get the working directory
MagicStrings.root_path = Environment.getExternalStorageDirectory().toString() + "/hari";
System.out.println("Working Directory = " + MagicStrings.root_path);
AIMLProcessor.extension = new PCAIMLProcessorExtension();
//Assign the AIML files to bot for processing
bot = new Bot("Hari", MagicStrings.root_path, "chat");
chat = new Chat(bot);
String[] args = null;
mainFunction(args);
'boolean b = jayDir.mkdirs();'。如果目录尚不存在,您应该只调用mkdirs。如果mkdirs返回false,则应该向用户显示敬酒信息。并返回。现在你盲目地继续。请尊重您的代码。 – greenapps
@greenapps我真的很陌生,我甚至无法检查复制是否真的发生。由于您陈述的问题,代码是否没有执行任务? –
你应该告诉我们什么工作,什么不工作。使用日志语句和吐司来查看会发生什么。做一些基本的调试。 – greenapps