• 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();
            }
    
        }
    
    }
  • 相关阅读:
    Pollard rho模板
    GDKOI2018游记
    BZOJ2599: [IOI2011]Race
    Codeforces914E. Palindromes in a Tree
    可以删点的并查集
    本月题量 180122晚-180222午
    51nod1238 最小公倍数之和 V3
    51nod1237 最大公约数之和 V3
    hdu5608:function
    51nod1244 莫比乌斯函数之和
  • 原文地址:https://www.cnblogs.com/yangchengyu314/p/5278023.html
Copyright © 2020-2023  润新知