【已解决】 IDEA 读取桌面创建的txt 和 IDEA内部创建txt文件效果不同
我又来了
大神们 有个问题就是 桌面创建txt和 IDEA创建txt 效果不同 是二者有什么不一样吗
我如果复制桌面创建的txt的话会显示找不到该文件
“Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [abc.txt] cannot be opened because it does not exist”
我测试了很久换路径改写法 最后我重新在IDEA中创建txt文件 立刻就读出出来了
这点大神门有什么见解吗
@Component public class AppService { @Value("classpath:/logo.txt")// logo idea创建就正常 、、abc 桌面创建就 not exist private Resource resource; private String abc; @PostConstruct public void init() throws IOException { try(BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream(),"UTF-8"))){ this.abc = reader.lines().collect(Collectors.joining()); System.out.println("abc = "+abc); } } }上代码