Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Java 11: use `Files.readString` to read a file to a String

オープン
#91 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Ouokki がすでに取り組んでいます。

2026年6月17日 から。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
42/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
静か
技術スタック
java
領域
tooling

調査の方向性

この issue には、Files.readAllBytes、BufferedReader、Scanner、および関連する API を使用する Java の例が示されていますが、リポジトリのファイルやテストは示されていません。まず、ファイル読み取りパターンを変換する既存の Java マイグレーションレシピを探し、次にカバレッジがどのようにテストされているかを確認してください。対応するパターンが Java 11 Files.readString に移行され、サポート対象のケースに対するテストが用意されていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

guava recipe uses-dataflow

There are many patterns to read all the contents of a File to a String

All the methods below will throw OOM if the file is larger than the available memory


// Java 7

String content = new String(Files.readAllBytes(Paths.get("file.txt")), StandardCharsets.UTF_8)`

// Using Guava 
import com.google.common.base.Charsets;
import com.google.common.io.Files;

String text = Files.toString(new File(path), Charsets.UTF_8);

// Using Files.readAllBytes

Path filePath = Path.of("file.txt");
String fileContent = "";

try
{
    byte[] bytes = Files.readAllBytes(Paths.get(filePath));
    fileContent = new String (bytes);
} 
catch (IOException e) 
{
    e.printStackTrace();
}

// Using BufferedReader (Java 6)

Path filePath = Path.of("file.txt");
String fileContent = "";

StringBuilder contentBuilder = new StringBuilder();
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) 
{

    String sCurrentLine;
    while ((sCurrentLine = br.readLine()) != null) 
    {
        contentBuilder.append(sCurrentLine).append("\n");
    }
} 
catch (IOException e) 
{
    e.printStackTrace();
}

fileContent = contentBuilder.toString();

// Using Commons IO

File file = new File("file.txt");

String content = FileUtils.readFileToString(file, "UTF-8");

// Using the Scanner class

  File file = new File("file.txt");
  StringBuilder fileContents = new StringBuilder();        

    try (Scanner scanner = new Scanner(file)) {
        while(scanner.hasNextLine()) {
            fileContents.append(scanner.nextLine() + System.lineSeparator());
        }

    }

// Using the Scanner class with String concatenation

  File file = new File("file.txt");
  String fileContents = ""  

    try (Scanner scanner = new Scanner(file)) {
        while(scanner.hasNextLine()) {
            fileContents = fileContents  + System.lineSeparator());
        }
     
    }


Starting with Java 11, all the patterns above could be replaced with


Path filePath = Path.of("file.txt");
String content = Files.readString(fileName);

主要言語
Java
スター
156
フォーク
129
平均マージ
7時間 21分
マージ済み PR(30日)
42

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

openrewrite/rewrite-migrate-java のほかの issue

openrewrite/rewrite-migrate-java の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。