Java模拟记事本

  • 闲的无聊,写了个Java代码模拟一下记事本
    public static void Demo_08() throws IOException{
    
    
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入记事本名字:");
        String s = sc.nextLine() + ".txt";
        System.out.println("此为记事本,请输入:");
        FileOutputStream fileOutputStream = new FileOutputStream(s);
        while(true){
    
    
            String s2 = sc.nextLine();
            if(s2.equals("QUIT")) break;
            fileOutputStream.write(s2.getBytes());
            fileOutputStream.write("\r\n".getBytes());
        }
    }

在这里插入图片描述
便可以生成一个helloworld.txt文件
在这里插入图片描述
成功模拟出了记事本功能

闲着无聊请勿模仿

猜你喜欢

转载自blog.csdn.net/younow22/article/details/113391438