主要记录下读取方法 。内容不重要
public class TypeSimpleService {
private Logger logger = LoggerFactory.getLogger(TypeSimpleService.class);
/**
* 读取deviceType映射表
*/
public void readText(){
/* 读取数据 */
InputStream inputStream = null;
BufferedReader br = null;
try {
inputStream = this.getClass().getResourceAsStream("/importSignal");
br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
String lineTxt;
while ((lineTxt = br.readLine()) != null) {//数据以逗号分隔
if(lineTxt.endsWith(",")){
lineTxt = lineTxt + " ";
}
String[] names = lineTxt.split(",");
try{
//格式 名称,说明,单位
String typeName = names[0];
String type = names[1];
String unit = names[2];
logger.info("");
}catch (Exception e){
logger.error("异常:{}",lineTxt);
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
logger.error("read errors :" + e);
}finally {
if(inputStream!=null){
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(br!=null){
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
logger.info("初始化 完成 !! ");
}
}
读取的文件:
importSignal内容: