0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Java ファイル 読み書き

Posted at

テキストファイルの読み方
FileWriterおよびFileReaderを使う

import java.io.*;

public class Main{ 
    public static void main(String[] args)throws Exception {
        FileReader fw=new FileReader("README.md");
        System.out.println("全てのデータを読んで表示します");
        int i=fw.read();//1文字のみ読み取れる
        while(i!=-1){
            char c=(char)i;//readから返される値はint型なのでキャストする
            System.out.print(c);
            i=fw.read();
        }
        System.out.println("ファイルの末尾に到達しました");
        fw.close();

    }

}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?