Reputation: 2370
when i run this code it gets me " java.io.FileNotFoundException: D:\qr.jpg (The filename, directory name, or volume label syntax is incorrect)" error
here is my code
try {
String kk = "fsdfsfs";
ByteArrayOutputStream out = QRCode.from(kk).to(ImageType.JPG).stream();
File f = new File("D:\\qr.jpg");
FileOutputStream fos = new FileOutputStream(f);
fos.write(out.toByteArray());
fos.flush();
} catch (Exception e) {
System.err.println(e);
}
Upvotes: 1
Views: 1910
Reputation: 1390
It seems that something funny is going on there. My advice will be to check if your program thinks the file is there and that it can write to it. Try the following and let me know what comes up:
try {
String kk = "fsdfsfs";
ByteArrayOutputStream out = QRCode.from(kk).to(ImageType.JPG).stream();
File f = new File("D:\\qr.jpg");
if(f.exists()) {
System.out.println("File exists");
}else {
f.createNewFile(); // if the file does not exist, create it
System.out.println("Created non-existing file");
}
if(f.canWrite()) {
System.out.println("File can be written to");
}
FileOutputStream fos = new FileOutputStream(f);
fos.write(out.toByteArray());
fos.flush();
} catch (Exception e) {
e.printStackTrace();
}
Upvotes: 1