我有一个完美运行的方法,但不是让它写入文件,而是如何让它将文件的每一行添加到列表中?(有些文件是 .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();
}
}