cn.hutool.core.io.FileUtil.getInputStream()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(704)

本文整理了Java中cn.hutool.core.io.FileUtil.getInputStream()方法的一些代码示例,展示了FileUtil.getInputStream()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.getInputStream()方法的具体详情如下:
包路径:cn.hutool.core.io.FileUtil
类名称:FileUtil
方法名:getInputStream

FileUtil.getInputStream介绍

[英]获得输入流
[中]获得输入流

代码示例

代码示例来源:origin: looly/hutool

/**
 * 获得一个文件读取器
 * 
 * @param file 文件
 * @param charsetName 字符集
 * @return BufferedReader对象
 * @throws IORuntimeException IO异常
 */
public static BufferedReader getReader(File file, String charsetName) throws IORuntimeException {
  return IoUtil.getReader(getInputStream(file), charsetName);
}

代码示例来源:origin: looly/hutool

/**
 * 从XML中读取对象 Reads serialized object from the XML file.
 * 
 * @param <T> 对象类型
 * @param source XML文件
 * @return 对象
 * @throws IOException IO异常
 */
public static <T> T readObjectFromXml(File source) throws IOException {
  return readObjectFromXml(new InputSource(FileUtil.getInputStream(source)));
}

代码示例来源:origin: looly/hutool

/**
 * 获得一个文件读取器
 * 
 * @param file 文件
 * @param charsetName 字符集
 * @return BufferedReader对象
 * @throws IORuntimeException IO异常
 */
public static BufferedReader getReader(File file, String charsetName) throws IORuntimeException {
  return IoUtil.getReader(getInputStream(file), charsetName);
}

代码示例来源:origin: looly/hutool

/**
 * 获得一个文件读取器
 * 
 * @param file 文件
 * @param charset 字符集
 * @return BufferedReader对象
 * @throws IORuntimeException IO异常
 */
public static BufferedReader getReader(File file, Charset charset) throws IORuntimeException {
  return IoUtil.getReader(getInputStream(file), charset);
}

代码示例来源:origin: looly/hutool

/**
 * 获得输入流
 * 
 * @param path 文件路径
 * @return 输入流
 * @throws IORuntimeException 文件未找到
 */
public static BufferedInputStream getInputStream(String path) throws IORuntimeException {
  return getInputStream(file(path));
}

代码示例来源:origin: looly/hutool

/**
 * 从XML中读取对象 Reads serialized object from the XML file.
 * 
 * @param <T> 对象类型
 * @param source XML文件
 * @return 对象
 * @throws IOException IO异常
 */
public static <T> T readObjectFromXml(File source) throws IOException {
  return readObjectFromXml(new InputSource(FileUtil.getInputStream(source)));
}

代码示例来源:origin: looly/hutool

/**
 * 获得输入流
 * 
 * @param path 文件路径
 * @return 输入流
 * @throws IORuntimeException 文件未找到
 */
public static BufferedInputStream getInputStream(String path) throws IORuntimeException {
  return getInputStream(file(path));
}

代码示例来源:origin: looly/hutool

/**
 * 获得一个文件读取器
 * 
 * @param file 文件
 * @param charset 字符集
 * @return BufferedReader对象
 * @throws IORuntimeException IO异常
 */
public static BufferedReader getReader(File file, Charset charset) throws IORuntimeException {
  return IoUtil.getReader(getInputStream(file), charset);
}

代码示例来源:origin: looly/hutool

/**
 * 获得一个文件读取器
 * 
 * @param path 文件Path
 * @param charset 字符集
 * @return BufferedReader对象
 * @throws IORuntimeException IO异常
 * @since 4.0.0
 */
public static BufferedReader getReader(Path path, Charset charset) throws IORuntimeException {
  return IoUtil.getReader(getInputStream(path), charset);
}

代码示例来源:origin: looly/hutool

/**
 * 获得一个文件读取器
 * 
 * @param path 文件Path
 * @param charset 字符集
 * @return BufferedReader对象
 * @throws IORuntimeException IO异常
 * @since 4.0.0
 */
public static BufferedReader getReader(Path path, Charset charset) throws IORuntimeException {
  return IoUtil.getReader(getInputStream(path), charset);
}

代码示例来源:origin: looly/hutool

/**
 * Gzip压缩文件
 * 
 * @param file 被压缩的文件
 * @return 压缩后的字节流
 * @throws UtilException IO异常
 */
public static byte[] gzip(File file) throws UtilException {
  BufferedInputStream in = null;
  try {
    in = FileUtil.getInputStream(file);
    return gzip(in, (int)file.length());
  } finally {
    IoUtil.close(in);
  }
}

代码示例来源:origin: looly/hutool

/**
 * Zlib压缩文件
 * 
 * @param file 被压缩的文件
 * @param level 压缩级别
 * @return 压缩后的字节流
 * @since 4.1.4
 */
public static byte[] zlib(File file, int level) {
  BufferedInputStream in = null;
  try {
    in = FileUtil.getInputStream(file);
    return zlib(in, level, (int)file.length());
  } finally {
    IoUtil.close(in);
  }
}

代码示例来源:origin: looly/hutool

/**
 * 构造
 * 
 * @param destFile 目标文件,可以不存在
 * @param sheetName sheet名,做为第一个sheet名并写出到此sheet,例如sheet1
 */
public ExcelWriter(File destFile, String sheetName) {
  this(destFile.exists() ? WorkbookUtil.createBook(FileUtil.getInputStream(destFile), true) : WorkbookUtil.createBook(StrUtil.endWithIgnoreCase(destFile.getName(), ".xlsx")), sheetName);
  this.destFile = destFile;
}

代码示例来源:origin: looly/hutool

/**
 * 构造
 * 
 * @param destFile 目标文件,可以不存在
 * @param sheetName sheet名,做为第一个sheet名并写出到此sheet,例如sheet1
 */
public ExcelWriter(File destFile, String sheetName) {
  this(destFile.exists() ? WorkbookUtil.createBook(FileUtil.getInputStream(destFile), true) : WorkbookUtil.createBook(StrUtil.endWithIgnoreCase(destFile.getName(), ".xlsx")), sheetName);
  this.destFile = destFile;
}

代码示例来源:origin: looly/hutool

/**
 * Gzip压缩文件
 * 
 * @param file 被压缩的文件
 * @return 压缩后的字节流
 * @throws UtilException IO异常
 */
public static byte[] gzip(File file) throws UtilException {
  BufferedInputStream in = null;
  try {
    in = FileUtil.getInputStream(file);
    return gzip(in, (int)file.length());
  } finally {
    IoUtil.close(in);
  }
}

代码示例来源:origin: looly/hutool

/**
 * 上传文件
 * 
 * @param file 文件
 * @param path 服务端路径
 * @param fileName 文件名
 * @return 是否上传成功
 */
public boolean upload(String path, String fileName, File file) {
  try (InputStream in = FileUtil.getInputStream(file)) {
    return upload(path, fileName, in);
  } catch (IOException e) {
    throw new FtpException(e);
  }
}

代码示例来源:origin: looly/hutool

/**
 * 上传文件
 * 
 * @param file 文件
 * @param path 服务端路径
 * @param fileName 文件名
 * @return 是否上传成功
 */
public boolean upload(String path, String fileName, File file) {
  try (InputStream in = FileUtil.getInputStream(file)) {
    return upload(path, fileName, in);
  } catch (IOException e) {
    throw new FtpException(e);
  }
}

代码示例来源:origin: looly/hutool

/**
 * 通过Sax方式读取Excel,同时支持03和07格式
 * 
 * @param path Excel文件路径
 * @param sheetIndex sheet序号
 * @param rowHandler 行处理器
 * @since 3.2.0
 */
public static void readBySax(String path, int sheetIndex, RowHandler rowHandler) {
  BufferedInputStream in = null;
  try {
    in = FileUtil.getInputStream(path);
    readBySax(in, sheetIndex, rowHandler);
  } finally {
    IoUtil.close(in);
  }
}

代码示例来源:origin: looly/hutool

/**
 * 添加文件到压缩包
 * 
 * @param file 需要压缩的文件
 * @param path 在压缩文件中的路径
 * @param out 压缩文件存储对象
 * @throws UtilException IO异常
 * @since 4.0.5
 */
private static void addFile(File file, String path, ZipOutputStream out) throws UtilException {
  BufferedInputStream in = null;
  try {
    in = FileUtil.getInputStream(file);
    addFile(in, path, out);
  } finally {
    IoUtil.close(in);
  }
}

代码示例来源:origin: looly/hutool

/**
 * 生成文件摘要<br>
 * 使用默认缓存大小,见 {@link IoUtil#DEFAULT_BUFFER_SIZE}
 * 
 * @param file 被摘要文件
 * @return 摘要bytes
 * @throws CryptoException Cause by IOException
 */
public byte[] digest(File file) throws CryptoException{
  InputStream in = null;
  try {
    in = FileUtil.getInputStream(file);
    return digest(in);
  } finally{
    IoUtil.close(in);
  }
}

相关文章

微信公众号

最新文章

更多