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();
    }
    }
    }

  • 相关阅读:
    底部导航栏
    判断手机是否连接网络
    瀑布流(圆角,卡片效果)
    列表卡片效果
    使用Glide改变图片的圆角
    条形码EAN-13码和EAN-8码的原理
    自定义底部弹窗
    【代码笔记】Java常识性基础补充(一)——赋值运算符、逻辑运算符、三元运算符、Scanner类、键盘输入、Random类、随机数
    【Android】9.0活动的生命周期(二)——实际代码演示
    【Android】8.0活动的生命周期(一)——理论知识、活动的启动方式
  • 原文地址:https://www.cnblogs.com/zszitman/p/5015347.html
Copyright © 2011-2022 走看看