1

private static void copydir(File src, File dest) throws IOException {
dest.mkdirs();
// 递归
// 1. 进入数据源
File[] files = src.listFiles();
// 2. 遍历数组
for (File file : files) {
if (file.isFile()) {
// 3. 判断文件,拷贝
FileInputStream fis = new FileInputStream(file);
FileOutputStream fos = new FileOutputStream(new File(dest, file.getName()));
byte[] bytes = new byte[1024];
int len;
while ((len = fis.read(bytes)) != -1) {
fos.write(bytes, 0, len);
}
fos.close();
fis.close();
} else {
// 4. 判断文件夹,递归
copydir(file, new File(dest, file.getName()));
}
}
}
2
//1.创建对象关联原始文件
FileInputStream fis = new FileInputStream("myio\\ency.jpg");
//2.创建对象关联加密文件
FileOutputStream fos = new FileOutputStream("myio\\redu.jpg");
//3.加密处理
int b;
while((b = fis.read()) != -1){
fos.write(b ^ 2);
}
//4.释放资源
fos.close();
fis.close();
3

//1.读取数据
FileReader fr = new FileReader("myio\\a.txt");
StringBuilder sb = new StringBuilder();
int ch;
while((ch = fr.read()) != -1){
sb.append((char)ch);
}
fr.close();
System.out.println(sb);
//2.排序
String str = sb.toString();
String[] arrStr = str.split("-");
ArrayList<Integer> list = new ArrayList<>();
for (String s : arrStr) {
int i = Integer.parseInt(s);
list.add(i);
}
Collections.sort(list);
System.out.println(list);
//3.写出
FileWriter fw = new FileWriter("myio\\a.txt");
for (int i = 0; i < list.size(); i++) {
if(i == list.size() - 1){
fw.write(list.get(i) + "");
}else{
fw.write(list.get(i) + "-");
}
}
//1.读取数据
FileReader fr = new FileReader("myio\\a.txt");
StringBuilder sb = new StringBuilder();
int ch;
while((ch = fr.read()) != -1){
sb.append((char)ch);
}
fr.close();
System.out.println(sb);
//2.排序
Integer[] arr = Arrays.stream(sb.toString())
.split("-") Stream<String>
.map(Integer::parseInt) Stream<Integer>
.sorted()
.toArray(Integer[]::new);
//3.写出
FileWriter fw = new FileWriter("myio\\a.txt");
String s = Arrays.toString(arr).replace(",", replacement: "-");
String result = s.substring(1, s.length() - 1);
fw.write(result);
fw.close();