0

完全に機能するメソッドがありますが、ファイルに書き込む代わりに、ファイルの各行をリストに追加するにはどうすればよいですか? (一部のファイルは .docx で、一部は .txt です)

private static void saveMultiple(Socket socket) {
    try {
        BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
        DataInputStream dis = new DataInputStream(bis);
        int filesCount = dis.readInt();
        File[] files = new File[filesCount];
        for (int i = 0; i < filesCount; i++) {
            long fileLength = dis.readLong();
            String fileName = dis.readUTF();
            files[i] = new File("/Users/.../Desktop/Data/" + fileName);
            FileOutputStream fos = new FileOutputStream(files[i]);
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            for (int x = 0; x < fileLength; x++) {
                bos.write(bis.read());
            }
            bos.close();
        }
        dis.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
4

1 に答える 1