公式jarパッケージ内のInのreadStrings()メソッドは使用する解決方法を提案しません.


起因:「アルゴリズム第四版」を勉強する時、いつもいくつかのアルゴリズム以外の小さな問題に出会います.例えば、本の中でダウンロードする必要があるライブラリです.今日は勉強の順序付けの時に、フレームワークmain()の方法の中のInのreadStrings()の方法が使えないことを発見しました.googleは長い間解決策を見つけられませんでした.algs 4のカバンの中にこの方法のソースコード(具体的な位置はedu.prinncon.cs.algs 4.In)を確認しました.コードは以下の通りです.
   /**
     * Reads all strings from a file and returns them as
     * an array of strings.
     *
     * @param      filename the name of the file
     * @return     the strings in the file
     * @deprecated Replaced by {@code new In(filename)}.{@link #readAllStrings()}.
     */
    @Deprecated
    public static String[] readStrings(String filename) {
        return new In(filename).readAllStrings();
    }
この方法は注釈@deprecated Replaced by {@code new In(filename)}.{@link #readAllStrings()}.によって見られます.この方法はすでに破棄されていますので、main()で文字列を読み取ったコードをString[] a = new In("tiny.txt").readAllStrings();に変更すれば、プログラムは正常に実行できます.
完全メール()の方法は以下の通りです.
    public static void main(String[] args) {
        String[] a = new In("tiny.txt").readAllStrings();
        System.out.println(a);
        sort(a);
        assert isSorted(a);
        show(a);
    }