Android以编程方式将文件夹移动到另一个文件夹
我想知道在安卓系统中如何将一个目录、一个文件夹而不是一个文件从一个目录移动到另一个目录。如何继续,我使用了此功能:Android以编程方式将文件夹移动到另一个文件夹,android,directory,Android,Directory,我想知道在安卓系统中如何将一个目录、一个文件夹而不是一个文件从一个目录移动到另一个目录。如何继续,我使用了此功能: private void moveFile(String inputPath, String inputFile, String outputPath) { InputStream in = null; OutputStream out = null; try { //create output directory if it doesn'
private void moveFile(String inputPath, String inputFile, String outputPath) {
InputStream in = null;
OutputStream out = null;
try {
//create output directory if it doesn't exist
File dir = new File (outputPath);
if (!dir.exists())
{
dir.mkdirs();
}
in = new FileInputStream(inputPath + inputFile);
out = new FileOutputStream(outputPath + inputFile);
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
in.close();
in = null;
// write the output file
out.flush();
out.close();
out = null;
// delete the original file
new File(inputPath + inputFile).delete();
}
catch (FileNotFoundException fnfe1) {
Log.e("tag", fnfe1.getMessage());
}
catch (Exception e) {
Log.e("tag", e.getMessage());
}
}
我设置了读写权限,但它只移动文件而不移动文件夹。要将文件夹移动到同一个文件系统还是其他文件系统?请检查文件重命名方法。我想把android手机存储器中的一些文件夹移到另一个文件夹中,例如/storage/emulated/0/Music,我想把它移到/storage/emulated/0/Movie/file。hole文件夹我是指Music中的现有文件:Help在创建dir文件夹后是否尝试使用dir.rename新建文件my/new/path?dir是一个预定义类还是我必须声明它