Read file and return contents as a string

@param f File to read
@return string contents of file
@throws MelcoePDPException
778655
public String fileToString(File f)
        throws MelcoePDPException {

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] bytes = new byte[1024];

        try {
            FileInputStream fis = new FileInputStream(f);
            int count = fis.read(bytes);
            while (count > -1) {
                out.write(bytes, 0, count);
                count = fis.read(bytes);
            }
            fis.close();
        } catch (IOException e) {
            throw new MelcoePDPException("Error reading file: "
                    + f.getName(), e);
        }
        return out.toString();

    }
1277630
static function parse_file( $f ){
		$src = file_get_contents( $f, true );
		if( $src === false ){
			throw new Exception("Cannot read file $f");
		}
		return self::parse_string( $src );
	}
405313
static private String readFile(String fileName) throws IOException {
    BufferedReader br = new BufferedReader(new FileReader(fileName));
    try {
      StringBuilder sb = new StringBuilder();
      String line = br.readLine();

      while (line != null) {
        sb.append(line);
        sb.append("\n");
        line = br.readLine();
      }
      return sb.toString();
    } finally {
      br.close();
    }
  }
686133
static function GetFileContent($filename,&$error = null,&$error_str = null){
		$error = false;
		$error_str = "";

		$out = "";
		
		settype($filename,"string");

		if(!is_file($filename)){
			$error = true;
			$error_str = "$filename is not a file";
			return null;		
		}

		$filesize = filesize($filename);
		if($filesize==0){ return ""; }

		$f = fopen($filename,"r");
		if(!$f){
			$error = false;
			$error_str = "can't open file $filename for writing";
			return $out;
		}
		$out = fread($f,$filesize);
		fclose($f);

		return $out;
	}
203910
public static String readFile(File file) throws IOException {
        StringBuilder content = new StringBuilder();
        String line;
        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
            while ((line = reader.readLine()) != null) {
                content.append(line).append("\r\n");
            }
        }
        return content.toString();
    }
722549
def read(fname):
    """"""
    content = None
    with open(os.path.join(here, fname)) as f:
        content = f.read()
    return content
1353673
private void read(final File f) throws IOException {
        final FileReader fr = new FileReader(f);
        final BufferedReader br = new BufferedReader(fr);
        String input = null;
        while ((input = br.readLine()) != null) {

            // Trim whitespace.
            input = input.trim();

            // Skip comments
            if (input.startsWith(COMMENT)) continue;

            final int idx = input.indexOf(NAME_VALUE_DELIMITER);
            if (idx == -1) continue;

            String name, value;
            try {
                name = input.substring(0, idx);
                value = input.substring(idx + 1);
            } catch (IndexOutOfBoundsException e) {
                continue;
            }
            name = name.trim();
            value = value.trim();

            cfgMap.put(name, valueSubstitution(value));
        }
        br.close();
    }
557587
public static String readString(File file, Charset charset) throws IOException {
        if (file == null || !file.isFile()) {
            return null;
        }
        StringBuilder fileContent = new StringBuilder();

        BufferedReader reader = null;
        try {
            InputStreamReader is = new InputStreamReader(new FileInputStream(file), charset);
            reader = new BufferedReader(is);
            String line = null;
            while ((line = reader.readLine()) != null) {
                if (!fileContent.toString().equals("")) {
                    fileContent.append("\r\n");
                }
                fileContent.append(line);
            }
            reader.close();
            return fileContent.toString();
        } finally {
            closeQuietly(reader);
        }
    }
257679
public static String read(final File file) throws IOException {
        final StringBuilder sb = new StringBuilder();

        try (
                final FileReader fr = new FileReader(file);
                final BufferedReader br = new BufferedReader(fr);
        ) {

            String sCurrentLine;

            while ((sCurrentLine = br.readLine()) != null) {
                sb.append(sCurrentLine);
            }
        }

        return sb.toString();
    }
448001
function _read_file($filename)
	{
		if ( file_exists($filename) && ($fd = @fopen($filename, 'rb')) ) {
			$contents = '';
			while (!feof($fd)) {
				$contents .= fread($fd, 8192);
			}
			fclose($fd);
			return $contents;
		} else {
			return false;
		}
	}
979906
public static String readFileToString(File file, final Charset charset) throws IOException {
        String line = null;
        BufferedReader reader = getBufferReader(file, charset);
        StringBuffer strBuffer = new StringBuffer();

        while ((line = reader.readLine()) != null) {
            strBuffer.append(line);
        }
        return strBuffer.toString();
    }
827243
public String read(String filename) throws IOException {
    Path p = new Path(filename);
    int size = (int) getMfs().getFileStatus(p).getLen();
    FSDataInputStream is = getMfs().open(p);
    byte[] content = new byte[size];
    is.readFully(content);
    return new String(content);
  }
175360
def file_contents(file_name):
    """"""
    curr_dir = os.path.abspath(os.path.dirname(__file__))
    with open(os.path.join(curr_dir, file_name)) as the_file:
        contents = the_file.read()
    return contents
735028
private static List<String> readAllLines(File f) throws IOException {
        BufferedReader r = new BufferedReader(new FileReader(f));
        try {
            List<String> result = new ArrayList<String>();
            String line;
            while ((line = r.readLine()) != null) {
                result.add(line);
            }
            return result;
        }  finally {
            r.close();
        }
    }
1329562
public function read($file)
    {
        $fp = fopen($file, 'r+');

        $contents = '';

        while ($part = fread($fp, 1024)) {
            $contents .= $part;
        }

        if (null !== $fp) {
            fclose($fp);
        }

        return $contents;
    }
27988
def read(fname):
    
    fpath = os.path.join(os.path.dirname(__file__), fname)
    with codecs.open(fpath, 'r', 'utf8') as fhandle:
        return fhandle.read().strip()
911093
public void read(File f) throws IOException {
        FileInputStream fis = new FileInputStream(f);
        try {
            read(new BufferedReader(new InputStreamReader(fis, "UTF-8")));
        } finally {
            IOUtils.closeQuietly(fis);
        }
    }