我有这段代码来打开一个文件,但我想知道是否可以打开它 UTF-8 文件
Resource usersResource = new ClassPathResource("users.csv");
@Before
public void setUp() throws IOException {
usersResource.getInputStream());
}
最佳答案
也许 InputStreamReader 可以通过以下方式为您解决这个问题:
new InputStreamReader(usersResource.getInputStream(), "UTF-8")
来自https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/InputStreamReader.html :
An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset.
请告诉我这是否有用。
-卡杰:)
关于java - 以UTF-8文件形式打开SpringBoot资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65338684/