java字符串写入读取

/**
 * Created by xabcd on 2019/3/18.
 */
import java.io.*;
public class writeandreadfile {
    public static void main(String args[]) {
        File f = new File("c:\\xxx.txt");
        Writer out = null;
        try {
            out = new FileWriter(f);

        } catch (IOException e) {
            e.printStackTrace();
        }
        String s = new String("Hello World!!!");
        try {
            out.write(s);
        } catch (IOException e2) {
            e2.printStackTrace();
        }
        try {
            out.close();
        } catch (IOException e9) {
            e9.printStackTrace();
        }


        Reader in = null;
        try {
            in = new FileReader(f);

        } catch (IOException e3) {
            e3.printStackTrace();
        }
//        String ss = new String ss[1024];
        char c1[] = new char[1024];
        int i = 0;
        try {
            i = in.read(c1);
//            in.close();
        }
        catch (IOException e4) {
            e4.printStackTrace();
        }

        try {
            in.close();
        }
        catch(IOException e8)
        {
            e8.printStackTrace();
        }
        System.out.println(new String(c1, 0, i));
        System.out.println(i);
//        System.out.println(c1);

    }
}

留下评论

您的邮箱地址不会被公开。 必填项已用 * 标注