java.io.IOException在从FTP客户端读取多个文件时发生。

huangapple 未分类评论49阅读模式
英文:

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!

huangapple
  • 本文由 发表于 2020年6月29日 14:00:15
  • 转载请务必保留本文链接:https://java.coder-hub.com/62632110.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定