zoukankan      html  css  js  c++  java
  • D盘创建TXT记事本

    
    
    package org.hanqi.ex;
    import java.io.*;
    public class TestFile2 {
    
        public static void main(String[] args) {
            try {
                FileOutputStream fos=new FileOutputStream("d:\test.txt");
            String str="大家下午好!";
            
                fos.write(str.getBytes());//覆盖写入
                //追加写入
                fos.close();
                FileInputStream fis=new FileInputStream("d:\test.txt");
                byte[]b=new byte[200];
                int i=fis.read(b);
                String str1=new String(b,0,i);
                System.out.println("读取内容:"+str1);
                fis.close();
            } catch (IOException e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();
            }
    
        }
    
    }
    
    
    
    package org.hanqi.ex;
    import java.io.*;
    public class TestFile3 {
    
        public static void main(String[] args) {
            try {
                //读取
                FileReader fr=new FileReader("d:\test.txt");
                char[]c=new char[200];
                int i=fr.read(c);
                String str=new String(c,0,i);
                System.out.println("读取内容"+str);
                fr.close();
                //写入
                FileWriter fw=new FileWriter("d:\test.txt",true);
                fw.write("
    新写入的内容");
                fw.close();
            } catch (Exception e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();
            }
    
        }
    
    }
  • 相关阅读:
    linux指令大全
    strcpy.strcmp.strlen.strcat函数的实现
    推箱子
    头文件string.h里的函数
    SVN 版本控制工具
    Nodejs 学习
    JavaScript基础知识复习
    CSS3 学习小结
    JSP中 JSTL
    JSP中的EL语言
  • 原文地址:https://www.cnblogs.com/yangchengyu314/p/5278023.html
Copyright © 2011-2022 走看看