复制方法给我这个错误:

“ 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)

10-04 12:34