package com.sf._02_字节流输出流; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Scanner; public class Test1 { /** * 要求在控制台当中录入你的 * 姓名: fanjialong * 年龄: xx * 身高: xx * 体重: xx * 注意: 每录入完信息就要信息追加到文件中 */ public static void main(String[] args) throws IOException { // 创建文件删除流写内容 FileOutputStream fileOutputStream = new FileOutputStream(new File("D:\\a.txt"),true); Scanner scanner = new Scanner(System.in); System.out.println("请录入你的姓名"); String name = scanner.next(); // 写入姓名 fileOutputStream.write(("姓名:"+name).getBytes()); // 写换行符 fileOutputStream.write(System.lineSeparator().getBytes()); System.out.println("请录入你的年龄"); String age = scanner.next(); // 写入姓名 fileOutputStream.write(("年龄:"+age).getBytes()); // 写换行符 fileOutputStream.write(System.lineSeparator().getBytes()); System.out.println("请录入你的身高"); String height = scanner.next(); // 写入姓名 fileOutputStream.write(("身高:"+height).getBytes()); // 写换行符 fileOutputStream.write(System.lineSeparator().getBytes()); System.out.println("请录入你的体重"); String weight = scanner.next(); // 写入姓名 fileOutputStream.write(("体重:"+weight).getBytes()); // 写换行符 fileOutputStream.write(System.lineSeparator().getBytes()); // 关闭资源 fileOutputStream.close(); } }