![](/img/trans.png)
[英]Write multiple Zip files to an OutputStream using IOUtils.copy method
[英]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個params方法。 https://poi.apache.org/apidocs/org/apache/poi/util/IOUtils.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.