課程
/后端開發(fā)
/Java
/Java生成二維碼
Path file=new File("D:/迅雷下載/img.png") .toPath();一直出錯是怎么回事
2017-01-06
源自:Java生成二維碼 6-2
正在回答
你知道那個包怎么引入呢?
//你的問題可能是引入的包不對import java.io.File;import java.nio.file.Path;import java.util.HashMap;import com.google.zxing.BarcodeFormat;import com.google.zxing.EncodeHintType;import com.google.zxing.MultiFormatWriter;import com.google.zxing.WriterException;import com.google.zxing.client.j2se.MatrixToImageWriter;import com.google.zxing.common.BitMatrix;import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;/**?* @descrption:生成二維碼?* @author pwu?*?*/public class CreateQRcode {?? ?public static void main(String[] args) {?? ??? ?int width=300;?? ??? ?int height=300;?? ??? ?String format="png";?? ??? ?String contents="http://idcbgp.cn";?? ??? ??? ??? ?//定義二維碼的參數(shù)?? ??? ?HashMap hints = new HashMap();?? ??? ?hints.put(EncodeHintType.CHARACTER_SET, "utf-8");?? ??? ?hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);?? ??? ?hints.put(EncodeHintType.MARGIN, 2);?? ??? ??? ??? ??? ??? ?try {?? ??? ??? ?BitMatrix bitMatrix =new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE, width, height,hints);?? ??? ??? ?Path file = new File("D:/Qrcode-zxing.png").toPath();?? ??? ??? ?MatrixToImageWriter.writeToPath(bitMatrix, format, file);?? ??? ??? ??? ??? ?} catch (Exception e) {?? ??? ??? ?// TODO Auto-generated catch block?? ??? ??? ?e.printStackTrace();?? ??? ?}?? ??? ??? ??? ??? ?}}
舉報
二維碼無處不在,自己動手用Java生成二維碼,三種生成方式任你選
8 回答Path file=new File(“d:/code/img.png”).toPath();寫完后顯示沒有Path這個包
2 回答path類型和file類型不匹配
1 回答path報錯
4 回答Path報錯
5 回答Path報錯
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2017-03-05
你知道那個包怎么引入呢?
2017-01-09
//你的問題可能是引入的包不對
import java.io.File;
import java.nio.file.Path;
import java.util.HashMap;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
/**
?* @descrption:生成二維碼
?* @author pwu
?*
?*/
public class CreateQRcode {
?? ?public static void main(String[] args) {
?? ??? ?int width=300;
?? ??? ?int height=300;
?? ??? ?String format="png";
?? ??? ?String contents="http://idcbgp.cn";
?? ??? ?
?? ??? ?//定義二維碼的參數(shù)
?? ??? ?HashMap hints = new HashMap();
?? ??? ?hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
?? ??? ?hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
?? ??? ?hints.put(EncodeHintType.MARGIN, 2);
?? ??? ?
?? ??? ?
?? ??? ?try {
?? ??? ??? ?BitMatrix bitMatrix =new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE, width, height,hints);
?? ??? ??? ?Path file = new File("D:/Qrcode-zxing.png").toPath();
?? ??? ??? ?MatrixToImageWriter.writeToPath(bitMatrix, format, file);
?? ??? ??? ?
?? ??? ?} catch (Exception e) {
?? ??? ??? ?// TODO Auto-generated catch block
?? ??? ??? ?e.printStackTrace();
?? ??? ?}
?? ??? ?
?? ??? ?
?? ?}
}