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

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

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

FileUtil.getWriter介绍

[英]获得一个带缓存的写入对象
[中]获得一个带缓存的写入对象

代码示例

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

/**
 * 构造
 * 
 * @param file CSV文件
 * @param charset 编码
 * @param isAppend 是否追加
 * @param config 写出配置,null则使用默认配置
 */
public CsvWriter(File file, Charset charset, boolean isAppend, CsvWriteConfig config) {
  this(FileUtil.getWriter(file, charset, isAppend), config);
}

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

/**
 * 构造
 * 
 * @param file CSV文件
 * @param charset 编码
 * @param isAppend 是否追加
 * @param config 写出配置,null则使用默认配置
 */
public CsvWriter(File file, Charset charset, boolean isAppend, CsvWriteConfig config) {
  this(FileUtil.getWriter(file, charset, isAppend), config);
}

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

/**
 * 获得一个打印写入对象,可以有print
 * 
 * @param file 文件
 * @param charset 字符集
 * @param isAppend 是否追加
 * @return 打印对象
 * @throws IORuntimeException IO异常
 */
public static PrintWriter getPrintWriter(File file, String charset, boolean isAppend) throws IORuntimeException {
  return new PrintWriter(getWriter(file, charset, isAppend));
}

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

/**
 * 获得一个带缓存的写入对象
 * 
 * @param file 输出文件
 * @param charsetName 字符集
 * @param isAppend 是否追加
 * @return BufferedReader对象
 * @throws IORuntimeException IO异常
 */
public static BufferedWriter getWriter(File file, String charsetName, boolean isAppend) throws IORuntimeException {
  return getWriter(file, Charset.forName(charsetName), isAppend);
}

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

/**
 * 获得一个打印写入对象,可以有print
 * 
 * @param path 输出路径,绝对路径
 * @param charset 字符集
 * @param isAppend 是否追加
 * @return 打印对象
 * @throws IORuntimeException IO异常
 */
public static PrintWriter getPrintWriter(String path, String charset, boolean isAppend) throws IORuntimeException {
  return new PrintWriter(getWriter(path, charset, isAppend));
}

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

/**
 * 获得一个带缓存的写入对象
 * 
 * @param file 输出文件
 * @param charsetName 字符集
 * @param isAppend 是否追加
 * @return BufferedReader对象
 * @throws IORuntimeException IO异常
 */
public static BufferedWriter getWriter(File file, String charsetName, boolean isAppend) throws IORuntimeException {
  return getWriter(file, Charset.forName(charsetName), isAppend);
}

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

/**
 * 获得一个打印写入对象,可以有print
 * 
 * @param file 文件
 * @param charset 字符集
 * @param isAppend 是否追加
 * @return 打印对象
 * @throws IORuntimeException IO异常
 */
public static PrintWriter getPrintWriter(File file, String charset, boolean isAppend) throws IORuntimeException {
  return new PrintWriter(getWriter(file, charset, isAppend));
}

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

/**
 * 获得一个打印写入对象,可以有print
 * 
 * @param path 输出路径,绝对路径
 * @param charset 字符集
 * @param isAppend 是否追加
 * @return 打印对象
 * @throws IORuntimeException IO异常
 */
public static PrintWriter getPrintWriter(String path, String charset, boolean isAppend) throws IORuntimeException {
  return new PrintWriter(getWriter(path, charset, isAppend));
}

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

/**
 * 获得一个打印写入对象,可以有print
 * 
 * @param path 输出路径,绝对路径
 * @param charset 字符集
 * @param isAppend 是否追加
 * @return 打印对象
 * @throws IORuntimeException IO异常
 * @since 4.1.1
 */
public static PrintWriter getPrintWriter(String path, Charset charset, boolean isAppend) throws IORuntimeException {
  return new PrintWriter(getWriter(path, charset, isAppend));
}

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

/**
 * 获得一个打印写入对象,可以有print
 * 
 * @param path 输出路径,绝对路径
 * @param charset 字符集
 * @param isAppend 是否追加
 * @return 打印对象
 * @throws IORuntimeException IO异常
 * @since 4.1.1
 */
public static PrintWriter getPrintWriter(String path, Charset charset, boolean isAppend) throws IORuntimeException {
  return new PrintWriter(getWriter(path, charset, isAppend));
}

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

/**
 * 获得一个带缓存的写入对象
 * 
 * @param path 输出路径,绝对路径
 * @param charset 字符集
 * @param isAppend 是否追加
 * @return BufferedReader对象
 * @throws IORuntimeException IO异常
 */
public static BufferedWriter getWriter(String path, Charset charset, boolean isAppend) throws IORuntimeException {
  return getWriter(touch(path), charset, isAppend);
}

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

/**
 * 获得一个带缓存的写入对象
 * 
 * @param path 输出路径,绝对路径
 * @param charsetName 字符集
 * @param isAppend 是否追加
 * @return BufferedReader对象
 * @throws IORuntimeException IO异常
 */
public static BufferedWriter getWriter(String path, String charsetName, boolean isAppend) throws IORuntimeException {
  return getWriter(touch(path), Charset.forName(charsetName), isAppend);
}

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

/**
 * 获得一个带缓存的写入对象
 * 
 * @param path 输出路径,绝对路径
 * @param charset 字符集
 * @param isAppend 是否追加
 * @return BufferedReader对象
 * @throws IORuntimeException IO异常
 */
public static BufferedWriter getWriter(String path, Charset charset, boolean isAppend) throws IORuntimeException {
  return getWriter(touch(path), charset, isAppend);
}

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

/**
 * 获得一个带缓存的写入对象
 * 
 * @param path 输出路径,绝对路径
 * @param charsetName 字符集
 * @param isAppend 是否追加
 * @return BufferedReader对象
 * @throws IORuntimeException IO异常
 */
public static BufferedWriter getWriter(String path, String charsetName, boolean isAppend) throws IORuntimeException {
  return getWriter(touch(path), Charset.forName(charsetName), isAppend);
}

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

/**
 * 持久化当前设置,会覆盖掉之前的设置
 * 
 * @param absolutePath 设置文件的绝对路径
 * @throws IORuntimeException IO异常,可能为文件未找到
 */
public void store(String absolutePath) throws IORuntimeException{
  Writer writer = null;
  try {
    writer = FileUtil.getWriter(absolutePath, charset, false);
    super.store(writer, null);
  } catch (IOException e) {
    throw new IORuntimeException(e, "Store properties to [{}] error!", absolutePath);
  } finally {
    IoUtil.close(writer);
  }
}

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

/**
 * 持久化当前设置,会覆盖掉之前的设置
 * 
 * @param absolutePath 设置文件的绝对路径
 * @throws IORuntimeException IO异常,可能为文件未找到
 */
public void store(String absolutePath) throws IORuntimeException{
  Writer writer = null;
  try {
    writer = FileUtil.getWriter(absolutePath, charset, false);
    super.store(writer, null);
  } catch (IOException e) {
    throw new IORuntimeException(e, "Store properties to [{}] error!", absolutePath);
  } finally {
    IoUtil.close(writer);
  }
}

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

/**
 * 将XML文档写入到文件<br>
 * 
 * @param doc XML文档
 * @param path 文件路径绝对路径或相对ClassPath路径,不存在会自动创建
 * @param charset 自定义XML文件的编码,如果为{@code null} 读取XML文档中的编码,否则默认UTF-8
 */
public static void toFile(Document doc, String path, String charset) {
  if (StrUtil.isBlank(charset)) {
    charset = doc.getXmlEncoding();
  }
  if (StrUtil.isBlank(charset)) {
    charset = CharsetUtil.UTF_8;
  }
  BufferedWriter writer = null;
  try {
    writer = FileUtil.getWriter(path, charset, false);
    write(doc, writer, true);
  } finally {
    IoUtil.close(writer);
  }
}

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

/**
 * 将XML文档写入到文件<br>
 * 
 * @param doc XML文档
 * @param path 文件路径绝对路径或相对ClassPath路径,不存在会自动创建
 * @param charset 自定义XML文件的编码,如果为{@code null} 读取XML文档中的编码,否则默认UTF-8
 */
public static void toFile(Document doc, String path, String charset) {
  if (StrUtil.isBlank(charset)) {
    charset = doc.getXmlEncoding();
  }
  if (StrUtil.isBlank(charset)) {
    charset = CharsetUtil.UTF_8;
  }
  BufferedWriter writer = null;
  try {
    writer = FileUtil.getWriter(path, charset, false);
    write(doc, writer, true);
  } finally {
    IoUtil.close(writer);
  }
}

代码示例来源:origin: cn.hutool/hutool-all

/**
 * 获得一个打印写入对象,可以有print
 * 
 * @param file 文件
 * @param charset 字符集
 * @param isAppend 是否追加
 * @return 打印对象
 * @throws IORuntimeException IO异常
 */
public static PrintWriter getPrintWriter(File file, String charset, boolean isAppend) throws IORuntimeException {
  return new PrintWriter(getWriter(file, charset, isAppend));
}

代码示例来源:origin: cn.hutool/hutool-all

/**
 * 获得一个带缓存的写入对象
 * 
 * @param path 输出路径,绝对路径
 * @param charset 字符集
 * @param isAppend 是否追加
 * @return BufferedReader对象
 * @throws IORuntimeException IO异常
 */
public static BufferedWriter getWriter(String path, Charset charset, boolean isAppend) throws IORuntimeException {
  return getWriter(touch(path), charset, isAppend);
}

相关文章

微信公众号

最新文章

更多