创建多级文件夹
final String ROOTPATH = "/Users/mac/Downloads"; // 默认文件下载的位置
@Test //创建多级文件夹
public void test1() {
String path = "com.id1.3rd"; // 这是文件夹,用.分割
String[] split = path.split("\\.");
String fullPath = ROOTPATH;
for (String s : split) {
fullPath += "/" + s;
File file = new File(fullPath);
file.mkdir();
}
复制移动文件到文件夹
undefined
/** * @param file 被移动的文件 * @param dictionary 移动到的目标文件夹 */public void copyAndRemoveFile1(String file, String dictionary) { try { FileInputStream in = new FileInputStream(file); FileOutputStream out = new FileOutputStream(dictionary+file.substring(file.lastIndexOf("/"),file.length())); int len = 0; byte[] buffer = new byte[1024]; while ((len = in.read(buffer)) != -1) { out.write(buffer, 0, len); } } catch (IOException e) { e.printStackTrace(); }}@Testpublic void test1() { String file = "/Users/mac/Desktop/artifactIdApplication.java"; // 必须是文件,不可以是文件夹 String dictionary = "/Users/mac/Desktop/未命名文件夹"; // 文件夹 copyAndRemoveFile1(file,dictionary);}
Original: https://www.cnblogs.com/cjin-01/p/16638494.html
Author: 2337
Title: IO流–创建文件夹,复制移动文件
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/712443/
转载文章受原作者版权保护。转载请注明原作者出处!