public class IOUtil extends Object
| 限定符和类型 | 类和说明 |
|---|---|
static class |
IOUtil.LineIterator
方便读取按行读取大文件
|
| 构造器和说明 |
|---|
IOUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
baseName(String path) |
static boolean |
deleteFile(String path)
删除本地文件
|
static String |
dirname(String path)
获取文件所在目录的路径
|
static byte[] |
getBytes(InputStream is) |
static InputStream |
getResourceAsStream(String path)
class.getResourceAsStream的wrapper,在资源不存在的情况下抛出IOException,
|
static String |
getSuffix(String name,
String delimiter)
获取最后一个分隔符的后缀
|
static boolean |
isFileExisted(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 InputStream |
newInputStream(String path)
创建输入流(经过IO适配器创建)
|
static OutputStream |
newOutputStream(String path)
创建输出流(经过IO适配器创建)
|
static byte[] |
readBytes(String path)
将整个文件读取为字节数组
|
static byte[] |
readBytesFromOtherInputStream(InputStream is)
将非FileInputStream的某InputStream中的全部数据读入到字节数组中
|
static int |
readBytesFromOtherInputStream(InputStream is,
byte[] targetArray)
从InputStream读取指定长度的字节出来
|
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 String |
readTxt(String file,
String charsetName) |
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) |
static void |
writeCustomNature(DataOutputStream out,
LinkedHashSet<Nature> customNatureCollector) |
static void |
writeLine(BufferedWriter bw,
String... params)
写数组,用制表符分割
|
public static LinkedList<String[]> readCsv(String path)
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 String readTxt(String file, String charsetName) throws IOException
IOExceptionpublic static byte[] readBytesFromOtherInputStream(InputStream is) throws IOException
is - IOExceptionpublic static int readBytesFromOtherInputStream(InputStream is, byte[] targetArray) throws IOException
is - 流targetArray - outputIOExceptionpublic static byte[] readBytesFromResource(String path) throws IOException
path - IOExceptionpublic 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, String separator)
public static boolean saveEntrySetToTxt(Set<Map.Entry<Object,Object>> entrySet, String path, String separator)
public static IOUtil.LineIterator readLine(String path)
public static boolean deleteFile(String path)
path - public static boolean isFileExisted(String path)
path - public static boolean isResource(String path)
path - public static BufferedWriter newBufferedWriter(String path) throws IOException
path - FileNotFoundExceptionUnsupportedEncodingExceptionIOExceptionpublic static BufferedReader newBufferedReader(String path) throws IOException
path - FileNotFoundExceptionUnsupportedEncodingExceptionIOExceptionpublic static BufferedWriter newBufferedWriter(String path, boolean append) throws FileNotFoundException, UnsupportedEncodingException
public static InputStream newInputStream(String path) throws IOException
path - IOExceptionpublic static OutputStream newOutputStream(String path) throws IOException
path - IOExceptionpublic static String getSuffix(String name, String delimiter)
name - delimiter - public static void writeLine(BufferedWriter bw, String... params) throws IOException
bw - params - IOExceptionpublic 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 - 异常表示加载失败public static void writeCustomNature(DataOutputStream out, LinkedHashSet<Nature> customNatureCollector) throws IOException
IOExceptionpublic static InputStream getResourceAsStream(String path) throws FileNotFoundException
path - FileNotFoundExceptionCopyright © 2014–2018 码农场. All rights reserved.