Java解决前端传入图片base64编码转换为图片写入本地

	File target = new File(targetDirectory, name);
	Decoder decoder = Base64.getDecoder();
	byte[] b = decoder.decode(base64);
	for (int i = 0; i < b.length; ++i) {
        if (b[i] < 0) {// 调整异常数据
            b[i] += 256;
        }
    }
	OutputStream os = new FileOutputStream(target);
	os.write(b);
	os.flush();
	os.close();

你可能感兴趣的:(Java,base64)