.toString().getBytes() "\r\n".getBytes() .toString()

package com.heima.test;

import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;

public class Test21 {

    /**.toString().getBytes() "\r\n".getBytes() .toString() * @param args * @throws IOException */
    public static void main(String[] args) throws IOException {
        File file = new File("E:\\黑马");

        String[] str = file.list(new FilenameFilter() {

            @Override//contains contentEquals
            public boolean accept(File dir, String name) {
                File file = new File(dir,name);
                return file.isFile() && file.getName().endsWith(".docx");
            }
        });
        for (String string : str) {
            System.out.println(string);
        }
        System.out.println("........................");
        File [] file2 = file.listFiles();
        for (File file3 : file2) {
            System.out.println(file3);
        }
        FileOutputStream fos = new FileOutputStream("first.txt");
        for (File file3 : file2) {
            fos.write(file3.toString().getBytes());
            fos.write("\r\n".getBytes());
        }
        fos.close();

        FileWriter fw = new FileWriter("second.txt");
        for (File file3 : file2) {
            fw.write(file3.toString());
            fw.write("\r\n");
        }
        fw.close();

        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("third.txt"));
        for (File file3 : file2) {
            bos.write(file3.toString().getBytes());
            bos.write("\r\n".getBytes());
        }
        bos.close();

        BufferedWriter bw = new BufferedWriter(new FileWriter("forth.txt"));
        for (File file3 : file2) {
            bw.write(file3.toString());
            bw.write("\r\n");
        }
        bw.close();
    }
}

你可能感兴趣的:(.toString().getBytes() "\r\n".getBytes() .toString())