|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectcom.hankcs.hanlp.corpus.io.IOUtil
public class IOUtil
一些常用的IO操作
| 嵌套类摘要 | |
|---|---|
static class |
IOUtil.LineIterator
方便读取按行读取大文件 |
| 构造方法摘要 | |
|---|---|
IOUtil()
|
|
| 方法摘要 | ||
|---|---|---|
static String |
dirname(String path)
获取文件所在目录的路径 |
|
static byte[] |
getBytes(InputStream is)
|
|
static InputStream |
getInputStream(String path)
智能获取InputStream,如果是资源文件则返回相应的InputStream |
|
static String |
getSuffix(String name,
String delimiter)
获取最后一个分隔符的后缀 |
|
static boolean |
isFileExists(String path)
判断文件是否存在 |
|
static boolean |
isResource(String path)
判断资源是否位于jar中 |
|
static void |
loadDictionary(BufferedReader br,
TreeMap<String,CoreDictionary.Attribute> storage)
将一个BufferedReader中的词条加载到词典 |
|
static TreeMap<String,CoreDictionary.Attribute> |
loadDictionary(String... pathArray)
加载词典,词典必须遵守HanLP核心词典格式 |
|
static BufferedReader |
newBufferedReader(String path)
创建一个BufferedReader |
|
static BufferedWriter |
newBufferedWriter(String path)
创建一个BufferedWriter |
|
static BufferedWriter |
newBufferedWriter(String path,
boolean append)
|
|
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
|
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)
|
|
static void |
writeLine(BufferedWriter bw,
String... params)
写数组,用制表符分割 |
|
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 构造方法详细信息 |
|---|
public IOUtil()
| 方法详细信息 |
|---|
public static boolean saveObjectTo(Object o,
String path)
o - path -
public static Object readObjectFrom(String path)
path -
public static String readTxt(String path)
path -
public static LinkedList<String[]> readCsv(String path)
public static boolean saveTxt(String path,
String content)
path - content -
public static boolean saveTxt(String path,
StringBuilder content)
public static <T> boolean saveCollectionToTxt(Collection<T> collection,
String path)
public static byte[] readBytes(String path)
path -
public static byte[] readBytesFromResource(String path)
throws IOException
path -
IOException
public static byte[] getBytes(InputStream is)
throws IOException
IOExceptionpublic static LinkedList<String> readLineList(String path)
public static LinkedList<String> readLineListWithLessMemory(String path)
path -
public static boolean saveMapToTxt(Map<Object,Object> map,
String path)
public static boolean saveMapToTxt(Map<Object,Object> map,
String path,
String separator)
public static boolean saveEntrySetToTxt(Set<Map.Entry<Object,Object>> entrySet,
String path,
String separator)
public static String dirname(String path)
path -
public static IOUtil.LineIterator readLine(String path)
public static boolean isFileExists(String path)
path -
public static boolean isResource(String path)
path -
public static InputStream getInputStream(String path)
throws FileNotFoundException
path -
FileNotFoundException
public static BufferedWriter newBufferedWriter(String path)
throws FileNotFoundException,
UnsupportedEncodingException
path -
FileNotFoundException
UnsupportedEncodingException
public static BufferedReader newBufferedReader(String path)
throws FileNotFoundException,
UnsupportedEncodingException
path -
FileNotFoundException
UnsupportedEncodingException
public static BufferedWriter newBufferedWriter(String path,
boolean append)
throws FileNotFoundException,
UnsupportedEncodingException
FileNotFoundException
UnsupportedEncodingException
public static String getSuffix(String name,
String delimiter)
name - delimiter -
public static void writeLine(BufferedWriter bw,
String... params)
throws IOException
bw - params -
IOException
public static TreeMap<String,CoreDictionary.Attribute> loadDictionary(String... pathArray)
throws IOException
pathArray - 词典路径,可以有任意个
IOException - 异常表示加载失败
public static void loadDictionary(BufferedReader br,
TreeMap<String,CoreDictionary.Attribute> storage)
throws IOException
br - 源storage - 储存位置
IOException - 异常表示加载失败
|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||