学习模拟jieba分词实现加载词库
问题1:
在resource目录下,使用以下路径,可以获取到File
String dict1 = “mydicts/mydict2.txt”;
但是通过这个路径无法获取到InputStream流,显示找不到文件,
//方式一:
// InputStream fileInputStream = this.getClass().getResourceAsStream("/" + dict1);
//方式二:
// String path = ClassLoader.getSystemClassLoader().getResource(dict1).getPath();
// FileInputStream fileInputStream = new FileInputStream(path);
//方式三:
// String path = this.getClass().getClassLoader().getSystemClassLoader().getResource(dict1).getPath();
// FileInputStream fileInputStream = new FileInputStream(path);
//方式四:
String path = ClassLoader.getSystemResource(dict1).getPath();
FileInputStream fileInputStream = new FileInputStream(path);
可以解决~