請(qǐng)問為什么系統(tǒng)提示path有問題?有大神能幫忙解決一下嗎
package irainbow.zxing;
import java.io.File;
import java.util.HashMap;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
//生成二維碼
public class creatQRcode {
??
public static ?void main(String[] args){
//定義二維碼的寬度和高度
int width=300;
int height=300;
String format="png";//指定圖片的格式為"png"
String content="rainbow,you must be happy evey day";//定義二維碼的內(nèi)容
//定義二維碼的參數(shù)
HashMap hints=new HashMap();
hints.put(EncodeHintType.CHARACTER_SET,"utf-8");
hints.put(EncodeHintType.ERROR_CORRECTION,ErrorCorrectionLevel.H);
? ? ? ? //設(shè)置容錯(cuò)等級(jí),二維碼糾錯(cuò)等級(jí)為H級(jí),容錯(cuò)等級(jí)越高,容量約小
hints.put(EncodeHintType.MARGIN,5);
? ? ? ? //邊框距離為5
//生成二維碼
try{
? BitMatrix bitMatrix = new MultiFormatWriter().encode(content,BarcodeFormat.QR_CODE,width,height,hints);
? Path file = new File("D:/code/1.png").toPath();//設(shè)置保存路徑
? MatrixToImageWriter.writeToPath(bitMatrix, format,file);//輸出圖像
}?
catch (Exception e) {e.printStackTrace();
}
}
}
2019-08-10
導(dǎo)入path包就行
2019-03-08
你path 在報(bào)錯(cuò)看不到嗎 導(dǎo)入io包進(jìn)去就有了
2018-11-05
你可能jdk版本過低
2018-08-23
你D盤下有沒有目錄code啊,一定要有
2018-08-04
想知道你解決了嗎
2018-07-31