Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法将 a 写入com.squareup.javapoet.JavaFile文件系统并确保文件始终使用 编码UTF-8?
com.squareup.javapoet.JavaFile
UTF-8
目前我正在使用com.squareup.javapoet.JavaFile#writeTo(java.io.File dir),但这使用当前虚拟机的默认编码。
com.squareup.javapoet.JavaFile#writeTo(java.io.File dir)
查看Javapoet的Github-Page,可以使用方法:
JavaFile.writeTo(PrintStream)
因此,您应该能够使用 UTF-8 创建 PrintStream 并像这样编写文件:
PrintStream stream = new PrintStream("YourTargetFile.java", "UTF-8"); yourJavaFileObject.writeTo(stream);