主要记录下读取方法 。内容不重要
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内容:

本文介绍了一种从特定文件中读取设备类型映射表的方法,通过使用Java的BufferedReader和InputStreamReader,实现对UTF-8编码的文本文件进行逐行读取并解析。该方法能够处理以逗号分隔的数据,将每行数据分解为格式名称、说明和单位三部分。
1387

被折叠的 条评论
为什么被折叠?



