UTF-8-BOM格式sql语句执行报错
用NotePad打开脚本,肉眼看没有问题,但是复制到navicat执行却INSERT报错,经过查证,发现是文件是UTF-8-BOM格式,应改为UTF-8无BOM格式。
解决方法一(适合单个文件)
NotePad打开脚本 --> 菜单“编码”–> “UTF-8无BOM编码” -->保存
解决方法二(适合多个文件)
用UTF8BOMConverte.java工具类统一转格式, 将UTF-8有BOM 批量转为 UTF-8无BOM文件格式
package com.xxx.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PushbackInputStream;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
/**
* utf-8有bom 批量转为 utf-8无bom 文件格式
*/
public class UTF8BOMConverter extends Reader {
private static final int BOM_SIZE = 4;
PushbackInputStream internalIn;//回退流对象
InputStreamReader internalIn2 = null;
String defaultEnc;//格式
/**
* @param in inputstream to be read
* @param defaultEnc default encoding if stream does not have
* BOM marker. Give NULL to use system-level default.
*/
UTF8BOMConverter(InputStream in, String defaultEnc) {
internalIn = new PushbackInputStream(in, BOM_SIZE);
this.defaultEnc = defaultEnc;
}
public static void main(String[] args) throws Exception {
String suffix = ".sql";//文件后缀名
List<String> paths = new ArrayList<String>();
paths = getAllFilePaths(new File("D:/test"), paths);//文件路径
List<String> pathList = new ArrayList<String>();
for (String path : paths) {