在对接快递鸟接口时报错 java.net.MalformedURLException: no protocol main方法测试成功,但整合ssm框架时报错。 从网上找解决方案说缺少 http 协议,但是我的控制台错误信息中的URL网址没错,直接粘贴网址正常访问。最终经检查,是因为我把地址写到配置wenj文件中的时候,默认是带bom的编辑器。这就会导致http协议错误。需要将配置文件转换成无bom UTF-8模式。
转换方法
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class UTF_8_BOM {
public static void main(String[] args) throws IOException {
File file = new File("F:\\MyWorkSpace\\Alipay\\kdn_hy_con\\src\\main\\resources\\properties\\KDNbase.properties");
File targetFile = new File("F:\\MyWorkSpace\\Alipay\\kdn_hy_con\\src\\main\\resources\\properties\\KDNbase1.properties");
if (!targetFile.exists())
{
targetFile.createNewFile();
}
BufferedReader br = null;
BufferedWriter bw = null;
br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(targetFile), "UTF-8"));
int i = 0;
String str = "";
while ((str = br.readLine()) != null)
{
if (i == 0)// 读取第一行,将前三个字节去掉,重新new个String对象
{
byte[] bytes = str.getBytes("UTF-8");
str = new String(bytes, 3, bytes.length - 3);
bw.write(str);
i++;
} else
bw.write(str);
}
br.close();
bw.close();
}
}
引用 https://blog.csdn.net/u013243986/article/details/52027499