Example usage for java.io BufferedReader close

List of usage examples for java.io BufferedReader close

Introduction

In this page you can find the example usage for java.io BufferedReader close.

Prototype

public void close() throws IOException 

Source Link

Usage

From source file:Main.java

public static StringBuilder ReadFileToString(String filename) {
    StringBuilder text = new StringBuilder();
    try {//  w  w w .j  av a2 s.c  o  m
        BufferedReader bProcFS = new BufferedReader(new FileReader(filename));
        String readLine = null;
        while ((readLine = bProcFS.readLine()) != null) {
            text.append(readLine);
            text.append("\n");
        }
        bProcFS.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return text;
}

From source file:ch.ralscha.extdirectspring.controller.RouterControllerFilterTest.java

@BeforeClass
public static void readJson() throws IOException {
    jsonList = new ArrayList<String>();
    InputStream is = RouterControllerFilterTest.class.getResourceAsStream("/filterjson.txt");
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    String line = null;//  w w w . j a v a2 s.c o  m
    while ((line = br.readLine()) != null) {
        jsonList.add(line);
    }
    br.close();
    is.close();
}

From source file:Main.java

/**
 * Read a text file//from  w ww  .j  a va  2 s .  c  o  m
 * 
 * @param file
 *            Which is read
 * 
 * @throws IOException
 *             Input/Output exceptions
 * 
 * @return contents of file
 */
public static String readTextFile(File file) throws IOException {
    BufferedReader reader = new BufferedReader(new FileReader(file));
    StringBuilder text = new StringBuilder();
    String line;
    while ((line = reader.readLine()) != null) {
        text.append(line);
        text.append("\n");
    }
    reader.close();
    return text.toString();
}

From source file:Main.java

public static String runCommand(String command) {
    try {/*from   ww  w.j  a  v  a 2 s .  c  o m*/
        StringBuffer output = new StringBuffer();
        Process p = Runtime.getRuntime().exec(command);
        BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line = "";
        while ((line = reader.readLine()) != null) {
            output.append(line + "\n");
        }
        reader.close();
        p.waitFor();
        return output.toString();
    } catch (InterruptedException | IOException e) {
        logError(e);
    }
    return "";
}

From source file:Main.java

public static Map<String, String> getCCMapFromFile() {
    Map result = new HashMap();
    try {//from  w w  w. j av a 2s . c om
        InputStreamReader insReader = new InputStreamReader(new FileInputStream(new File("tb_category")),
                "utf-8");
        BufferedReader bufReader = new BufferedReader(insReader);
        String temp;
        while ((temp = bufReader.readLine()) != null) {
            String[] tempA = temp.split("#######");
            result.put(tempA[0], tempA[1]);
        }
        bufReader.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:com.lunix.cheata.utils.file.FileManager.java

public static String readFile(String fileName) {
    try {//from  www.  ja  v  a 2s  .c o  m
        File file = new File(getDir().getAbsolutePath(), fileName);
        String fileContents;
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(new DataInputStream(new FileInputStream(file))));
        fileContents = FileUtils.readFileToString(file);
        reader.close();
        return fileContents;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return "";
}

From source file:Main.java

/**
 * This method fetches data from a given url
 *
 * @param strUrl Url from which the data will be fetched
 * @return A String representing the resource obtained in the connection
 * @throws IOException If something went wrong with the connection
 *//*from   www  . j  a  v  a2 s  .c  o  m*/
public static String getDataFromUrl(String strUrl) throws IOException {
    InputStream iStream;
    HttpURLConnection urlConnection;
    URL url = new URL(strUrl);

    // Creating an http connection to communicate with url
    urlConnection = (HttpURLConnection) url.openConnection();

    // Connecting to url
    urlConnection.connect();

    // Reading data from url
    iStream = urlConnection.getInputStream();

    BufferedReader br = new BufferedReader(new InputStreamReader(iStream));

    StringBuilder sb = new StringBuilder();

    String line;
    while ((line = br.readLine()) != null) {
        sb.append(line);
    }
    br.close();
    iStream.close();
    urlConnection.disconnect();
    return sb.toString();
}

From source file:Main.java

/**
 * Send the Http's request with the address of url
 * @param String url//from  ww w  . j  a v  a 2 s . c o m
 * @return String
 */
public static String getHttpRequest(String url) {
    //should use the StringBuilder or StringBuffer, String is not used.
    StringBuffer jsonContent = new StringBuffer();
    try {
        URL getUrl = new URL(url);
        HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection();
        connection.connect();
        //Getting the inputting stream, and then read the stream.
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String lines = "";
        while ((lines = reader.readLine()) != null) {
            jsonContent.append(lines);
        }
        reader.close();
        connection.disconnect();
    } catch (Exception e) {
        e.printStackTrace();
    }
    //ScanningActivity.log("getHttpRequest(): " + content);
    //BooksPutIn.log("getHttpRequest(): " + content);
    return jsonContent.toString();
}

From source file:com.dss886.nForumSDK.http.ResponseProcessor.java

/**
 * HttpResponse?String//from   www .  j a  va2s  .  c  o m
 * @throws IllegalStateException, IOException
 * */
public static String getStringFromResponse(HttpResponse response) throws IllegalStateException, IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    StringBuffer sb = new StringBuffer();
    String line;
    while ((line = in.readLine()) != null) {
        sb.append(line);
    }
    in.close();
    return sb.toString();
}

From source file:Clima.Clima.java

public static String getHTML(String urlToRead) throws Exception {
    StringBuilder result = new StringBuilder();
    URL url = new URL(urlToRead);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("GET");
    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String line;/*  w w  w.  j  a v a  2 s  . c  o m*/
    while ((line = rd.readLine()) != null) {
        result.append(line);
    }
    rd.close();
    return result.toString();
}