一、情景:須要將硬代碼寫到文件中,這樣之後改動只需改動靈活html
1)txt文件,須要將這code字符串讀到代碼中,保存成數組java
2)導包:pom.xml添加依賴:數組
<dependency> <groupId>org.ini4j</groupId> <artifactId>ini4j</artifactId> <version>0.5.4</version> </dependency>
3)要讀取文件,確定要複製路徑spa
4)讀取並打印出:code
public static void main(String[] args) throws IOException { String fileName = "E:\\workspeace\\pkpm\\sgserver-service\\sgserver-construction\\construction-service\\src\\main\\resources\\codeFile"; Wini ini = new Wini(new File(fileName)); String codeType = ini.get("qrCode", "code"); System.out.println(codeType); String[] types = StringUtils.split(codeType, ","); for (String type : types) { System.out.println(type); } }
5)結果:server
6)想了解ini文件,參考這篇博客xml