zoukankan      html  css  js  c++  java
  • java i/o读写

    package ioput;

    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;

    public class aaa {

    /*public static void main(String[] args) {
    args = new String[]{"a","b","c"};
    for (int i = 0; i < args.length; i++) {
    System.out.println("args[" + i + "] is <" + args[i] + ">");
    }
    }*/

    /*public static void main(String args[]) {
    int b;
    try {
    System.out.println("please Input:");
    while ((b = System.in.read()) != -1) {
    System.out.print((char) b);
    }
    } catch (IOException e) {
    System.out.println(e.toString());
    }
    } */

    /* public static void main(String args[]) {
    String s;
    // 创建缓冲区阅读器从键盘逐行读入数据
    InputStreamReader ir = new InputStreamReader(System.in);
    BufferedReader in = new BufferedReader(ir);
    System.out.println("Unix系统: ctrl-d 或 ctrl-c 退出"
    + " Windows系统: ctrl-z 退出");
    try {
    // 读一行数据,并标准输出至显示器
    s = in.readLine();
    // readLine()方法运行时若发生I/O错误,将抛出IOException异常
    while (s != null) {
    System.out.println("Read: " + s);
    s = in.readLine();
    }
    // 关闭缓冲阅读器
    in.close();
    } catch (IOException e) { // Catch any IO exceptions.
    e.printStackTrace();
    }
    }*/
    //从磁盘读数据
    /*public static void main(String[] args){
    try {
    File file = new File("d:/aaa/gbk.txt");
    InputStream fileStream = new FileInputStream(file);
    InputStreamReader read = new InputStreamReader(fileStream,"utf-8");
    BufferedReader bufferedReader = new BufferedReader(read);
    String text = null;
    while((text =bufferedReader.readLine())!=null){
    System.out.println(text);
    }
    read.close();
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }*/
    //数据写入磁盘
    public static void main(String[] args){
    String path = "d:/tr/rt";
    File f = new File(path);
    if(!f.exists()){
    f.mkdirs();
    }
    String fileName="test.txt";
    File file = new File(f,fileName);
    if(!file.exists()){
    try {
    file.createNewFile();
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    String s = "1234567890";
    try {
    BufferedWriter writer = new BufferedWriter(new FileWriter(file));
    writer.write(s);
    writer.close();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }

  • 相关阅读:
    contest hunter5105 Cookies
    bzoj2599: [IOI2011]Race
    poj1741 Tree
    bzoj2527: [Poi2011]Meteors
    bzoj3673: 可持久化并查集 by zky&&3674: 可持久化并查集加强版
    bzoj2741: 【FOTILE模拟赛】L
    bzoj3110: [Zjoi2013]K大数查询
    bzoj1901: Zju2112 Dynamic Rankings
    bzoj2821: 作诗(Poetize)
    poj1417 True Liars
  • 原文地址:https://www.cnblogs.com/zszitman/p/5015347.html
Copyright © 2011-2022 走看看