国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

香港云服务器
服務(wù)器之家 - 編程語(yǔ)言 - JAVA教程 - java中關(guān)于文本文件的讀寫(xiě)方法實(shí)例總結(jié)

java中關(guān)于文本文件的讀寫(xiě)方法實(shí)例總結(jié)

2020-01-15 14:14生活真美好 JAVA教程

這篇文章主要介紹了java中關(guān)于文本文件的讀寫(xiě)方法,實(shí)例總結(jié)了Java針對(duì)文本文件讀寫(xiě)的幾種常用方法,并對(duì)比了各個(gè)方法的優(yōu)劣及特點(diǎn),具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例總結(jié)了java中關(guān)于文本文件的讀寫(xiě)方法。分享給大家供大家參考,具體如下:

寫(xiě)文本數(shù)據(jù)

方法 一:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import java.io.*;
public class A {
  public static void main(String args[]) {
    FileOutputStream out;
    PrintStream ps;
    try {
      out = new FileOutputStream("a.txt");
      ps = new PrintStream(out);
      ps.println("qun qun.");
      ps.println("fei fei");
      ps.close();
    } catch (Exception e) {
      System.out.println(e.toString());
    }
  }
}

方法 二:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import java.io.*;
public class B {
  public static void main(String args[]) {
    FileWriter fw;
    PrintWriter pw;
    try {
      fw = new FileWriter("b.txt");
      pw = new PrintWriter(fw);
      pw.print("qunqu n ");
      pw.println("feiefi ss");
      pw.print("qunqu n ");
      pw.close();
      fw.close();
    } catch (IOException e) {
      System.out.println(e.toString());
    }
  }
}

方法三:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import java.io.*;
public class C {
  public static void main(String args[]) {
    String str_written = "This is a simple example";
    try {
      FileWriter fwriter = new FileWriter("c.txt");
      BufferedWriter bfwriter = new BufferedWriter(fwriter);
      bfwriter.write(str_written, 0, str_written.length());
      bfwriter.flush();
      bfwriter.close();
    } catch (IOException e) {
      System.out.println(e.toString());
    }
  }
}

附注:方法一和方法二,方法三都是在操作文本文件不存在的時(shí)候?qū)?chuàng)建,否則,當(dāng)覆蓋之!

另;方法三

BufferedWriter將文本寫(xiě)入字符輸出流,緩沖各個(gè)字符,從而提供單個(gè)字符、數(shù)組和字符串的高效寫(xiě)入。

附:追加寫(xiě)入:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import java.io.*;
public class C {
  public static void main(String args[]) {
    String str_written = "This is a simple example";
    try {
      FileWriter fwriter = new FileWriter("c.txt", true);
      BufferedWriter bfwriter = new BufferedWriter(fwriter);
      bfwriter.newLine();
      bfwriter.write(str_written, 0, str_written.length());
      bfwriter.flush();
      bfwriter.close();
    } catch (IOException e) {
      System.out.println(e.toString());
    }
  }
}

讀文本數(shù)據(jù)

方法一:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import java.io.*;
public class A {
  public static void main(String args[]) {
    try {
      FileInputStream fstream = new FileInputStream("a.txt");
      DataInputStream in = new DataInputStream(fstream);
      while (in.available() != 0) {
        String a = in.readLine();
        System.out.println(a);
        System.out.println(a.length());
      }
      in.close();
    } catch (Exception e) {
      System.out.println(e.toString());
    }
  }
}

方法二:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import java.io.*;
public class B {
  public static void main(String args[]) {
    try {
      FileReader fr = new FileReader("a.txt");
      BufferedReader br = new BufferedReader(fr);
      String str;
      int count = 0;
      while ((str = br.readLine()) != null) {
        count++;
        System.out.println(count + " : " + str);
      }
      br.close();
      fr.close();
    } catch (Exception e) {
      System.out.println(e.toString());
    }
  }
}

附:方法二的能夠高效的實(shí)現(xiàn)文本數(shù)據(jù)的讀出

希望本文所述對(duì)大家Java程序設(shè)計(jì)有所幫助。

延伸 · 閱讀

精彩推薦
463
主站蜘蛛池模板: 亚洲视频在线免费观看 | 99国产精品99久久久久久 | 欧美日韩一区二 | 日韩午夜在线 | 日韩在线观看第一页 | 国产精品无码永久免费888 | 成av在线 | 免费精品 | 一区二区三区高清不卡 | 欧美综合一区 | 国产精品99久久久久久动医院 | 成人羞羞视频免费 | 日本在线视频一区 | 天天操一操 | 美女一区二区三区 | 亚洲免费一区 | 激情欧美一区二区三区中文字幕 | 国产成人一级毛片 | 秋霞av电影 | 青娱乐99 | 97国产精品 | 九九综合九九 | 一区二区三区精品视频 | 婷婷激情久久 | 欧美电影免费观看高清 | 国产精品毛片一区视频播不卡 | 亚洲黄色在线 | 亚洲狠狠丁香婷婷综合久久久 | 国产精品99久久免费观看 | 涩涩视频观看 | 中文字幕日韩一区 | 91免费在线 | 日本久久网 | 精品国产网站 | 日韩精品一区二区在线观看视频 | 亚洲www啪成人一区二区 | 综合亚洲精品 | 国产露脸国语对白在线 | 日韩aaa视频 | 糈精国产xxxx在线观看 | 在线a电影 |