1个回答
展开全部
如下代码,向D盘temp文件夹下的 test.txt 文件中写入 Hello World!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; public class App { public static void main(String[] args) throws IOException { File file = new File( "d:\\temp\\test.txt" ); try ( FileOutputStream outputStream = new FileOutputStream(file); OutputStreamWriter streamWriter = new OutputStreamWriter(outputStream) ) { streamWriter.write( "Hello World!" ); streamWriter.flush(); } } } |
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询