复制方法给我这个错误:
“ IOUtils类型中的方法副本(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);
}
}
答案 0 :(得分:1)
我想你的意思是导入org.apache.commons.io.IOUtils
而不是org.apache.poi.util.IOUtils
。
前者有很多copy()
种方法,后者只有copy(InputStream, OutputStream)
。
答案 1 :(得分:1)
来自apache POI的IOUtils仅包含2个params方法。 https://poi.apache.org/apidocs/org/apache/poi/util/IOUtils.html