请问为什么系统提示path有问题?有大神能帮忙解决一下吗

来源:6-2 使用zxing生成二维码

阿阿阿果阿

2018-07-31 19:51

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";//定义二维码的内容

//定义二维码的参数

HashMap hints=new HashMap();

hints.put(EncodeHintType.CHARACTER_SET,"utf-8");

hints.put(EncodeHintType.ERROR_CORRECTION,ErrorCorrectionLevel.H);

        //设置容错等级,二维码纠错等级为H级,容错等级越高,容量约小

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();//设置保存路径

  MatrixToImageWriter.writeToPath(bitMatrix, format,file);//输出图像

catch (Exception e) {e.printStackTrace();

}

}

}


写回答 关注

6回答

  • 慕村3302840
    2019-08-10 19:26:12

    导入path包就行

  • 我可不是一只圆滚滚的大熊猫
    2019-03-08 14:41:34

    你path 在报错看不到吗 导入io包进去就有了

  • 乘舟于学海飘摇
    2018-11-05 17:41:57

    你可能jdk版本过低

  • 慕斯卡4710254
    2018-08-23 09:59:17

    你D盘下有没有目录code啊,一定要有

  • 慕粉2242270
    2018-08-04 20:00:46

    想知道你解决了吗


    阿阿阿果阿

    没有呢

    2018-08-08 13:00:20

    共 1 条回复 >

  • 阿阿阿果阿
    2018-07-31 19:56:52

    https://img1.mukewang.com/5b604e6c0001fe0408170318.jpg程序是这样的

Java生成二维码

二维码无处不在,自己动手用Java生成二维码,三种生成方式任你选

84564 学习 · 224 问题

查看课程

相似问题