IOUtils 复制方法无法正常工作

IOUtils copy method is not working properly

复制方法给我这个错误:

"类型 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).

来自 apache POI 的 IOUtils 仅包含 2 个参数方法。 https://poi.apache.org/apidocs/org/apache/poi/util/IOUtils.html