com.hankcs.hanlp.corpus.io
类 IOUtil

java.lang.Object
  继承者 com.hankcs.hanlp.corpus.io.IOUtil

public class IOUtil
extends Object

一些常用的IO操作

作者:
hankcs

嵌套类摘要
static class IOUtil.LineIterator
          方便读取按行读取大文件
 
构造方法摘要
IOUtil()
           
 
方法摘要
static byte[] getBytes(InputStream is)
           
static InputStream getInputStream(String path)
          智能获取InputStream,如果是资源文件则返回相应的InputStream
static boolean isFileExists(String path)
          判断文件是否存在
static boolean isResource(String path)
          判断资源是否位于jar中
static byte[] readBytes(String path)
          将整个文件读取为字节数组
static byte[] readBytesFromResource(String path)
          将资源中的一个资源读入byte数组
static LinkedList<String[]> readCsv(String path)
           
static IOUtil.LineIterator readLine(String path)
           
static LinkedList<String> readLineList(String path)
           
static LinkedList<String> readLineListWithLessMemory(String path)
          用省内存的方式读取大文件
static Object readObjectFrom(String path)
          反序列化对象
static String readTxt(String path)
          一次性读入纯文本
static
<T> boolean
saveCollectionToTxt(Collection<T> collection, String path)
           
static boolean saveEntrySetToTxt(Set<Map.Entry<Object,Object>> entrySet, String path, String separator)
           
static boolean saveMapToTxt(Map<Object,Object> map, String path)
           
static boolean saveMapToTxt(Map<Object,Object> map, String path, String separator)
           
static boolean saveObjectTo(Object o, String path)
          序列化对象
static boolean saveTxt(String path, String content)
          快速保存
static boolean saveTxt(String path, StringBuilder content)
           
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

IOUtil

public IOUtil()
方法详细信息

saveObjectTo

public static boolean saveObjectTo(Object o,
                                   String path)
序列化对象

参数:
o -
path -
返回:

readObjectFrom

public static Object readObjectFrom(String path)
反序列化对象

参数:
path -
返回:

readTxt

public static String readTxt(String path)
一次性读入纯文本

参数:
path -
返回:

readCsv

public static LinkedList<String[]> readCsv(String path)

saveTxt

public static boolean saveTxt(String path,
                              String content)
快速保存

参数:
path -
content -
返回:

saveTxt

public static boolean saveTxt(String path,
                              StringBuilder content)

saveCollectionToTxt

public static <T> boolean saveCollectionToTxt(Collection<T> collection,
                                              String path)

readBytes

public static byte[] readBytes(String path)
将整个文件读取为字节数组

参数:
path -
返回:

readBytesFromResource

public static byte[] readBytesFromResource(String path)
                                    throws IOException
将资源中的一个资源读入byte数组

参数:
path -
返回:
抛出:
IOException

getBytes

public static byte[] getBytes(InputStream is)
                       throws IOException
抛出:
IOException

readLineList

public static LinkedList<String> readLineList(String path)

readLineListWithLessMemory

public static LinkedList<String> readLineListWithLessMemory(String path)
用省内存的方式读取大文件

参数:
path -
返回:

saveMapToTxt

public static boolean saveMapToTxt(Map<Object,Object> map,
                                   String path)

saveMapToTxt

public static boolean saveMapToTxt(Map<Object,Object> map,
                                   String path,
                                   String separator)

saveEntrySetToTxt

public static boolean saveEntrySetToTxt(Set<Map.Entry<Object,Object>> entrySet,
                                        String path,
                                        String separator)

readLine

public static IOUtil.LineIterator readLine(String path)

isFileExists

public static boolean isFileExists(String path)
判断文件是否存在

参数:
path -
返回:

isResource

public static boolean isResource(String path)
判断资源是否位于jar中

参数:
path -
返回:

getInputStream

public static InputStream getInputStream(String path)
                                  throws FileNotFoundException
智能获取InputStream,如果是资源文件则返回相应的InputStream

参数:
path -
返回:
抛出:
FileNotFoundException


Copyright © 2014–2015 码农场. All rights reserved.