Java: Lesen von Bytes aus einer .txt-Datei LINE BY LINE

Bitte schauen Sie sich den folgenden Code an

    import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class FileCopy2
{    public static void main(String[]args) 
    {        
        try
        {

              //First in here, we are trying to get the bytes from the file


        File file = new File("D:/burn/preview.mp3"); //The File you need to get

        byte bufferFile[] = new byte[(int)file.length()]; //Creating a byte array, which has the exact size of the file

        BufferedInputStream bi = new BufferedInputStream(new FileInputStream(file));// Creating Buffers for IO

        bi.read(bufferFile, 0, bufferFile.length);//Reading the file

        bi.close();//Closing Buffer




        //Then in here, we are writing those bytes to a text file

        BufferedOutputStream bu = new BufferedOutputStream(new FileOutputStream("C:/Users/Yohan/Desktop/test.txt")); //The output Location
        bu.write(bufferFile, 0, bufferFile.length);//Writing the file
        bu.flush();//Flushing the buffer
        bu.close();//Closing the Buffer

        System.out.println("Done Copieng");



        //Here we are trying to WRITE number of .txt files containing the byte details..In other words, I am breaking the file into peaces

        BufferedReader br = new BufferedReader(new FileReader("C:/Users/Yohan/Desktop/test.txt"));
        BufferedWriter bw = null;

        String content = "";
        int count = 1;
        while((content = br.readLine())!=null)
        {

            bw = new BufferedWriter(new FileWriter("C:/Users/Yohan/Desktop/output4/file"+count+".txt"));
            bw.write(content);
            bw.flush();
            bw.close();


            count++;
            System.out.println("Running");

        }
        System.out.println("-----------------------Done-----------------------------");



            //NOW I NEED TO read all the generated .txt file and create the original file back. How to do it? //
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}

Dort bekomme ich zuerst die Bytes einer Datei und schreibe sie in eine Textdatei. Dann habe ich diese Textdatei gelesen, zeilenweise gelesen und für jede Zeile eine eigene TXT-Datei erstellt.Jetzt ist das ursprüngliche Programm in Tausende von Dateien aufgeteilt. Jetzt muss ich alle .txt-Dateien lesen und die .txt-Datei neu generieren. Ich weiß nicht, wie ich das letzte machen soll. Wie kann ich das machen? Bitte helfen Sie!

Antworten auf die Frage(1)

Ihre Antwort auf die Frage