zoukankan      html  css  js  c++  java
  • java文件读写常用方法

    // TODO Auto-generated method stub
    //File file = new File("D:\Android\workspace\Practice1\src\test4", "new1.txt");
    //String str = file.getName();
    //file.delete();

    // try{
    // Runtime rt = Runtime.getRuntime();
    //
    // File file = new File("D:\Program Files (x86)\CodeBlocks", "codeblocks.exe");
    // System.out.println("打开codeblocks");
    // rt.exec(file.getAbsolutePath());
    // file = new File("D:\酷狗\KGMusic", "KuGou.exe");
    // System.out.println("打开酷狗");
    // rt.exec(file.getAbsolutePath());
    // file = new File("D:\净网大师\ADSafe", "ADSafeSvc.exe");
    // System.out.println("打开净网大师");
    // rt.exec(file.getAbsolutePath());
    // }catch(Exception e){
    // System.out.println(e);
    // }


    // try{
    // File f = new File("D:\Android\workspace\Practice1\src\test4", "file.txt");
    // FileInputStream in = new FileInputStream(f);
    // int n = -1;
    // byte [] a= new byte[100];
    //
    // while((n = in.read(a, 0, 100)) != -1){
    // String s = new String(a, 0, n);
    // System.out.print(s);
    // }
    // in.close();
    // }
    // catch(Exception e){
    // System.out.println(e);
    // }

    // try{
    // byte []b = "我是你爸爸".getBytes();
    // File file = new File("D:\Android\workspace\Practice1\src\test4", "empty.txt");
    // FileOutputStream out = new FileOutputStream(file);
    // out.write(b);
    // out.close();
    // out = new FileOutputStream(file, true);
    // b = ",当文件字符输出流的构造方法中有true参数时,可以在文件末尾追加文字".getBytes();
    // out.write(b);
    //
    // out.close();
    //
    // }
    // catch(Exception e){
    // System.out.println(e);
    // }

    // byte []b = "我是你大爷".getBytes();
    // System.out.println(b);

    // File sourceFile = new File("D:\Android\workspace\Practice1\src\test4","a.txt");
    // File targetFile = new File("D:\Android\workspace\Practice1\src\test4","b.txt");
    //
    // char c[] = new char[19];
    // try{
    // Reader in = new FileReader(sourceFile);
    // Writer out = new FileWriter(targetFile, true);
    // int n = -1;
    // while((n = in.read(c))!= -1){
    // out.write(c, 0, n);
    // }
    // out.flush();//使缓冲区的内容马上写入目的地
    // out.close();
    // }catch(Exception e){
    // System.out.println(e);
    //
    // }

    // try{
    //
    // FileReader inOne = new FileReader("D:\Android\workspace\Practice1\src\test4\a.txt");
    // BufferedReader bufferedRead = new BufferedReader(inOne);
    //
    // FileWriter tofile = new FileWriter("D:\Android\workspace\Practice1\src\test4\to.txt");
    // BufferedWriter bufferedWrite = new BufferedWriter(tofile);
    //
    // String str = null;
    //
    // while((str = bufferedRead.readLine()) != null){
    // StringTokenizer fenxi = new StringTokenizer(str);
    // str = str + "单词个数:" + fenxi.countTokens();
    // bufferedWrite.write(str);
    // bufferedWrite.newLine();
    // }
    //
    // bufferedWrite.close();
    // tofile.close();
    // bufferedRead.close();
    // inOne.close();
    //
    //
    // }
    // catch(Exception e){
    // System.out.println(e);
    // }

    //
    // RandomAccessFile inAndOut = null;
    // int data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 111};
    // try{
    // inAndOut = new RandomAccessFile("D:\Android\workspace\Practice1\src\test4\random.txt", "rw");
    // for(int i = 0; i < data.length; i++){
    // inAndOut.writeInt(data[i]);
    // }
    //
    // for(long i = data.length - 1; i >= 0; i--){
    // inAndOut.seek(i * 4);
    // System.out.printf(" %d", inAndOut.readInt());
    // }
    // inAndOut.close();
    // }catch(Exception e){
    // System.out.println(e);
    // }
    //

    System.out.println(Math.round(-13.4));
    char 坏 = '坏';

    ok:while(true){
    while(true){
    System.out.println("我只循环一次");
    break ok;
    }
    }

    int num = (int)Math.random() * 100;


    //break String s = null;
    //char 好 = 坏;

    }

  • 相关阅读:
    python学习day15 内置函数
    python学习day14 生成器表达式
    python学习day13 迭代器,生成器
    python学习day12 装饰器进阶
    gulp管理angular2项目 配置文件
    angular2 基于webpack环境搭建
    jQuery dataTable 操作个人使用总结
    报错:Could not reserve enough space for object heap error
    CSS布局之圣杯布局和双飞翼布局
    CSS 之 Position定位
  • 原文地址:https://www.cnblogs.com/liaoxiaolao/p/7690819.html
Copyright © 2011-2022 走看看