File.separator 分割付
String dir = savePath + File.separator+Common.QRCODE+File.separator + subpath +File.separator + batchCode;
File outputFile = new File(dir);//根據路建立文件類實例
outputFile.mkdirs();//建立文件夾路徑
boolean mkdir() 建立此抽象路徑名指定的目錄。 好比建立E:\\text 沒有 E 報錯返回false
boolean mkdirs() 建立此抽象路徑名指定的目錄,包括全部必需但不存在的父目錄。 好比建立E:\\text 沒有 E建立Eweb
String str = String.format("http://app.diandiancaidan.com/scan.do?m=nscan&qrCode=%s", nn);
QrCodeHelper.saveqrCode(dir,str, nn, "0");
public static void saveqrCode(String dir, String data, String filename,String flag){ try { int width = 640; int height = 640; if("1".equals(flag)){ width =580; height = 580; }else if("2".equals(flag)){ width =586; height = 586; } String format = "png"; Hashtable<EncodeHintType, String> hints= new Hashtable<EncodeHintType, String>(); hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); BitMatrix bitMatrix = new MultiFormatWriter().encode(data, BarcodeFormat.QR_CODE, width, height,hints); //圖片 File outputFile = new File(dir + "/" + filename + ".png"); //以前創建的路徑加上圖片路徑 MatrixToImageWriter.writeToFile(bitMatrix, format, outputFile); //createQRCode(bitMatrix, format, outputFile); } catch(Exception e) { e.printStackTrace(); } }
本地傳輸測試使用 String path=(Class.class.getClass().getResource("/").getPath()+String.format(Common.agentPath,super.userId,Common.normal)).substring(1);
D:/DDCDSS/management/web/target/classes/ static/upload/shop/shop-1/thumb/normalapp
<img class="layui-upload-img" id="${imgId}old" src="'../../${value}"/> static/upload/shop/shop-1/thumb/normal/1542249116725.jpg