Java Text File Read readTextFile(final DataInputStream is)

Here you can find the source of readTextFile(final DataInputStream is)

Description

Read file as text file return as US-ASCII string

License

Open Source License

Parameter

Parameter Description
is DataInputStream

Exception

Parameter Description
IOException if there is any problem with the DataInputStream

Return

String

Declaration

public static String readTextFile(final DataInputStream is) throws IOException 

Method Source Code

//package com.java2s;
/**/*from w ww . j a  v a 2 s . com*/
 *
 * Open Realm of Stars Game Project
 * Copyright (C) 2016  Tuomo Untinen
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see http://www.gnu.org/licenses/
 *
 *
 * Generic IO Utilities
 *
 */

import java.io.DataInputStream;

import java.io.IOException;

public class Main {
    /**
     * Read file as text file return as US-ASCII string
     * @param is DataInputStream
     * @return String
     * @throws IOException if there is any problem with the DataInputStream
     */
    public static String readTextFile(final DataInputStream is) throws IOException {
        byte[] dataBuf = new byte[is.available()];
        is.readFully(dataBuf);
        return new String(dataBuf, "US-ASCII");
    }
}

Related

  1. getFileContents(String pFileName)
  2. loadAsString(String location)
  3. readFile(String filePath)
  4. readFile(String path)
  5. readTextFile(File file, int max, String ellipsis)
  6. readTextFile(final String path, final String enc)
  7. readTextFile(InputStream inStream)
  8. readTextFile(String fileName)
  9. readTextFile(String fn)