Java InputStreamReader Read readFileSB(File f)

Here you can find the source of readFileSB(File f)

Description

read File SB

License

Open Source License

Declaration

public static StringBuffer readFileSB(File f) throws IOException 

Method Source Code


//package com.java2s;
import java.io.BufferedReader;

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static StringBuffer readFileSB(File f) throws IOException {
        InputStream in = new FileInputStream(f);
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        StringBuffer sb = new StringBuffer();
        try {//from  ww w.j av  a2  s .  com
            readFile(reader, sb);
        } finally {
            reader.close();
        }
        return sb;
    }

    public static String readFile(InputStream in) throws IOException {
        StringBuffer sb = new StringBuffer();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        try {
            readFile(reader, sb);
        } finally {
            reader.close();
        }
        return sb.toString();
    }

    public static String readFile(File f) throws IOException {
        StringBuffer sb = new StringBuffer();
        InputStream in = new FileInputStream(f);
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        try {
            readFile(reader, sb);
        } finally {
            reader.close();
        }
        return sb.toString();
    }

    public static void readFile(BufferedReader reader, StringBuffer sb) throws IOException {
        String line = null;
        do {
            line = reader.readLine();
            if (line != null) {
                sb.append(line);
                sb.append("\n");
            }
        } while (line != null);
    }
}

Related

  1. readFileLineByLine(final File filePath)
  2. readFileList(File file)
  3. readFileOneLine(String filename, String keyInLine)
  4. readFileOrResource(String source)
  5. readFiles(String[] files, String encoding)
  6. readFileToLines(File file)
  7. readFileToList(String fileName, String codeing)
  8. readFileToSet(String filePath, String fileEncoding)
  9. readFileUtf8(IFile file)