import com.google.zxing.WriterException;
import org.apache.commons.*;
import sun.misc.IOUtils;
import sun.nio.ch.IOUtil;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.*;
class HtmlWriter {
private final PrintWriter out;
private final File dir;
private int iota=1;
public HtmlWriter(File dir) throws IOException {
this.dir = dir;
this.out = new PrintWriter(new File(dir,"out.html"));
InputStream x = HtmlWriter.class.getResourceAsStream("/badges.html");
// out.println(IOUtils.toString(HtmlWriter.class.getResourceAsStream("/badges.html")));
System.out.print(IOUtils.toString(HtmlWriter.class.getResourceAsStream("/badges.html")));
}
public void add(String firstName, String lastName, String company, String email, String tel) throws IOException, WriterException {
VCardBuilder vc = new VCardBuilder();
vc.with("N",firstName+" "+lastName)
.with("ORG", company)
.with("TEL", tel)
.with("EMAIL", email);
System.out.println(vc.toString());
vc.writeQRCode(new File(dir,String.format("qr%04d.png",iota)));
out.printf(
"<div class='badge'>\n" +
" <img class='qrcode' src='qr%04d.png'>\n" +
" <div class='cblogo'></div>\n"+
" <div class='firstName'>%s</div>\n" +
" <div class='lastName'>%s</div>\n" +
" <div class='company'>%s</div>\n" +
"</div>\n", iota, firstName, lastName, company
);
iota++; }
public void close() {
out.println("</body></html>");
out.close();
}
}
答案 0 :(得分:0)
您已导入sun.misc.IOUtils
,但您可能想要org.apache.commons.io.IOUtils
。 Apache IOUtils有the toString()
method you want.
要在maven项目中使用它,请包含以下依赖项:
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
或从项目主页下载jar文件:https://commons.apache.org/proper/commons-io/download_io.cgi