Here you can find the source of readFile(File file)
Parameter | Description |
---|---|
file | to be read |
Parameter | Description |
---|---|
IOException | an exception |
public static String readFile(File file) throws IOException
//package com.java2s; /*//from w w w .j a v a 2s . c o m * This file is part of easyFPGA. * Copyright 2013-2015 os-cillation GmbH * * easyFPGA 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 3 of the License, or * (at your option) any later version. * * easyFPGA 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 easyFPGA. If not, see <http://www.gnu.org/licenses/>. * */ import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Main { /** system-dependent line separator */ public static final String LS = System.getProperty("line.separator"); /** * Read string from a file * * @param file to be read * @return string containing file content or empty string on file not found * @throws IOException */ public static String readFile(File file) throws IOException { BufferedReader reader; try { reader = new BufferedReader(new FileReader(file)); } catch (FileNotFoundException e) { return ""; } StringBuilder sb = new StringBuilder(); String line = reader.readLine(); while (line != null) { sb.append(line); sb.append(LS); line = reader.readLine(); } String fileString = sb.toString(); reader.close(); return fileString; } }