gpt4 book ai didi

java - IOUtils 复制方法无法正常工作

转载 作者:行者123 更新时间:2023-12-02 03:57:28 25 4
gpt4 key购买 nike

复制方法给我这个错误:

IOUtils 类型中的方法 copy(InputStream, OutputStream) 不适用于参数 (FileInputStream, StringWriter, String)

...即使我有 3 个参数并且 IOUtils 确实有

copy(InputStream, Writer, String) 方法。

这是我的代码:

import java.awt.BorderLayout;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.StringWriter;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;

import org.apache.poi.util.IOUtils;

@SuppressWarnings("serial")
public class AboutDialog extends JFrame {
private final String fileLocation = "resources/Contents.html";
private FileInputStream htmlStream;
private JLabel lblMessage;

public AboutDialog() {
String message;
setType(Type.POPUP);
setTitle("About");
setResizable(false);
setEnabled(false);
getContentPane().setLayout(new BorderLayout(0, 0));
try {
htmlStream = new FileInputStream(fileLocation);
StringWriter writer = new StringWriter();
IOUtils.copy(htmlStream, writer, "UTF-8");
message = writer.toString();
lblMessage = new JLabel(message);
lblMessage.setHorizontalAlignment(SwingConstants.CENTER);
getContentPane().add(lblMessage);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}

public void display() {
JOptionPane.showMessageDialog(null, lblMessage);
}
}

最佳答案

我猜你的意思是导入org.apache.commons.io.IOUtils而不是org.apache.poi.util.IOUtils

前者有很多 copy() 方法,后者只有 copy(InputStream, OutputStream)

关于java - IOUtils 复制方法无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35297785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com