向文件中写东西
作者:互联网
package com.company;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// write your code here
Scanner scanner=new Scanner(System.in);//建立一个从键盘输入的扫描器
FileOutputStream fos=null;
try{
fos=new FileOutputStream("D:\\练习.txt");
String str=scanner.next();
fos.write(str.getBytes());
}catch(IOException e)
{
e.printStackTrace();
}finally{
try{
fos.close();
}catch(IOException e)
{
e.printStackTrace();
}
}
}
}
标签:文件,java,Scanner,fos,东西,printStackTrace,import,中写,scanner 来源: https://www.cnblogs.com/yuyu-qing/p/15508518.html