Java FileInputStream Read loadTxtFile(String fileName)

Here you can find the source of loadTxtFile(String fileName)

Description

load Txt File

License

Open Source License

Declaration

public static String loadTxtFile(String fileName) throws FileNotFoundException, IOException 

Method Source Code

//package com.java2s;
/**/*from w ww. ja  va 2  s.c  om*/
 * Copyright 2010 ZTEsoft Inc. All Rights Reserved.
 *
 * This software is the proprietary information of ZTEsoft Inc.
 * Use is subject to license terms.
 * 
 * $Tracker List
 * 
 * $TaskId: $ $Date: 9:24:36 AM (May 9, 2008) $comments: create 
 * $TaskId: $ $Date: 3:56:36 PM (SEP 13, 2010) $comments: upgrade jvm to jvm1.5 
 *  
 *  
 */

import java.io.*;

public class Main {

    public static String loadTxtFile(String fileName) throws FileNotFoundException, IOException {
        byte[] bfs = loadFile(fileName);
        String ret = new String(bfs, "UTF-8");
        return ret;
    }

    public static byte[] loadFile(String fileName) throws FileNotFoundException, IOException {
        byte[] retBytes = new byte[0];
        File file = new File(fileName);

        FileInputStream fs = new FileInputStream(fileName);
        int fileLen = (int) file.length();
        retBytes = new byte[fileLen];
        fs.read(retBytes);
        fs.close();

        return retBytes;
    }
}

Related

  1. loadContents(File file)
  2. loadData(File f)
  3. loadFolderFromJar(String path)
  4. loadRes(String res)
  5. loadStackableItems(String fileName)
  6. readFile( String filename)
  7. readFile(File f)
  8. readFile(File f)
  9. readFile(File f)