Tag: 可靠性

用Java复制和移动文件,解释和比较不同的方法

我实现了文件操作function,我注意到Java提供了多种复制和移动文件的技术。 您可以在下面找到代码片段,简要介绍这些方法: 方法#1: File from = new File(src.getPath()); File to = new File(dst.getPath()); from.renameTo(to); 方法#2: FileChannel inChannel = new FileInputStream(src).getChannel(); FileChannel outChannel = new FileOutputStream(dst).getChannel(); inChannel.transferTo(0, inChannel.size(), outChannel); 方法#3: InputStream in = getContentResolver().openInputStream(selectedImageUri); OutputStream out = new FileOutputStream(“/sdcard/wallpapers/” + wall); byte[] buffer = new byte[1024]; int read; while ((read = in.read(buffer)) != -1) { out.write(buffer, […]