如题,今天用字节流读取问件事发现读出来的每行都带了
字样,在idea中有这个但eclipse中无,很奇怪,可能是控制台的编码问题吧。
解决方案:此字符为“\r”的字符串显示,替换掉即可 replace("\r","")
// Base64编码
public String getBase64FromFile(File f) throws IOException {
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(f);
byte[] b = new byte[fileInputStream.available()];
fileInputStream.read(b);
return new BASE64Encoder().encode(b);
} finally {
try {
if (fileInputStream != null) {
fileInputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}