亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

Path file=new File(“d:/code/img.png”).toPath();寫完后顯示沒有Path這個包

為什么我的Path file=new File(“d:/code/img.png”).toPath();這句話報錯呢?一寫完Path下面就出現紅色下劃線,顯示壓根就沒有這個包,但我前面那些步驟都和老師視頻里寫的一樣,都沒報錯,就這一句會報錯,這是為啥啊?

正在回答

7 回答

直接用File就好了,不需要Path

0 回復 有任何疑惑可以回復我~

jdk使用1.8依然如此

0 回復 有任何疑惑可以回復我~

JDK問題

0 回復 有任何疑惑可以回復我~
package?com;
import?java.nio.file.Path;
import?java.util.HashMap;
import?com.google.zxing.BarcodeFormat;
import?com.google.zxing.EncodeHintType?;
import?com.google.zxing.MultiFormatReader;
import?com.google.zxing.MultiFormatWriter;
import?com.google.zxing.client.j2se.MatrixToImageWriter;
import?com.google.zxing.common.BitMatrix;
import?com.google.zxing.pdf417.decoder.ec.ErrorCorrection;
import?com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import?java.io.File;

public?class?QRcode?{
????public?static?void?main(String[]?args)?{
????????int?width?=?300;
????????int?height?=?300;
????????String?format?=?"png";
????????String?content?=?"www.xianlaiwan.cn";

????????//?定義二維碼參數
????????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(content,?BarcodeFormat.QR_CODE,?width,?height,?hints);
????????????Path?file?=?new?File("./Qrcode.png").toPath();
????????????MatrixToImageWriter.writeToPath(bitMatrix,?format,?file?);

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


????}
}


0 回復 有任何疑惑可以回復我~
#1

創心

路徑是 mac 寫的, 。windows 請看老師具體修改
2017-12-08 回復 有任何疑惑可以回復我~

Path file = new File("D:/Qrcode-zxing.png").toPath();我也是 File和topath()下面一直有紅線

0 回復 有任何疑惑可以回復我~

JDK版本太低了,換個1.8的

0 回復 有任何疑惑可以回復我~

因為你d盤下沒有創建code這個文件夾


0 回復 有任何疑惑可以回復我~
#1

慕粉2049205449 提問者

不是啊,我在d盤下建了code這個文件夾,報錯還是老樣子
2017-07-25 回復 有任何疑惑可以回復我~
#2

Imooc_YunLong 回復 慕粉2049205449 提問者

這個問題你解決了沒
2017-11-15 回復 有任何疑惑可以回復我~
#3

慕粉2242270 回復 慕粉2049205449 提問者

想知道怎么解決的
2018-08-04 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

Path file=new File(“d:/code/img.png”).toPath();寫完后顯示沒有Path這個包

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號