英文:
java.io.IOException while reading multiple file from FTP Client
问题
我有下面的readFile方法。我有一个包含文件名和时间戳的HashMap。使用for循环,我正在尝试读取HashMap中所有文件的内容。
public static void readFile(String remoteFile, FTPClient ftp) throws Exception {
InputStream iStream = ftp.retrieveFileStream(remoteFile);
BufferedInputStream bInf = new BufferedInputStream(iStream);
int bytesRead;
byte[] buffer = new byte[1024];
String fileContent = null;
while ((bytesRead = bInf.read(buffer)) != -1) {
fileContent = new String(buffer, 0, bytesRead);
}
System.out.println(fileContent);
}
意图:将每个文件的内容作为byte[]传递给另一个应用程序,但遇到以下问题:
# srvDEVSchoolInfo的属性
[srvDEVSchoolInfo]
IS_PAYLOAD_LOG_REQD = true
IS_VALIDATION_ENABLED = true
java.io.IOException: 流已关闭
at java.io.BufferedInputStream.getInIfOpen(未知来源)
at java.io.BufferedInputStream.fill(未知来源)
at java.io.BufferedInputStream.read1(未知来源)
at java.io.BufferedInputStream.read(未知来源)
at java.io.FilterInputStream.read(未知来源)
at FileReadFTP.readFile(FileReadFTP.java:252)
at FileReadFTP.getFileContentFromFTP(FileReadFTP.java:74)
at FileReadFTP.main(FileReadFTP.java:37)
所有文件(TOML)都包含虚拟数据。我错过了什么?我不是Java专家,任何帮助都将是很棒的。谢谢!
英文:
I have the below method of readFile. I have a HashMap that contain filenames along with their timestamp.
Using for loop, I'm trying to read contents of all files in the HashMap.
public static void readFile(String remoteFile, FTPClient ftp) throws Exception {
InputStream iStream =ftp.retrieveFileStream(remoteFile);
BufferedInputStream bInf = new BufferedInputStream(iStream);
int bytesRead;
byte[] buffer = new byte[1024];
String fileContent = null;
while ((bytesRead = bInf.read(buffer)) != -1) {
fileContent = new String(buffer, 0, bytesRead);
}
System.out.println(fileContent);
}
Intention: Pass content of each file as byte[] to another application but facing below issue:
# Properties of srvDEVSchoolInfo
[srvDEVSchoolInfo]
IS_PAYLOAD_LOG_REQD = true
IS_VALIDATION_ENABLED = true
java.io.IOException: Stream closed
at java.io.BufferedInputStream.getInIfOpen(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at java.io.FilterInputStream.read(Unknown Source)
at FileReadFTP.readFile(FileReadFTP.java:252)
at FileReadFTP.getFileContentFromFTP(FileReadFTP.java:74)
at FileReadFTP.main(FileReadFTP.java:37)
All the files (TOML) contain dummy data. What am I missing? Not an expert in java, any help would be great. Thanks!
专注分享java语言的经验与见解,让所有开发者获益!
评论