【问题标题】:JCIFS - SMBFileOutputStream as UTF8JCIFS - SMBFileOutputStream 作为 UTF8
【发布时间】:2018-01-18 03:22:53
【问题描述】:

如何将文件写入为 UTF8?我已经设置了系统属性,但没有工作。

下面是示例代码。

SmbFileOutputStream sfos = null;
        try {
            NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(wipDomain,wipUsername,wipPassword);
            System.setProperty("jcifs.encoding", "UTF8");
            logger.info("Path: " +path);
            SmbFile sFile = new SmbFile(path, auth);
            sfos = new SmbFileOutputStream(sFile);
            sfos.write(content.getBytes());
            return true;
        } catch (IOException e) {

            logger.error(e.getMessage());
            return false;
        } finally {
            if (sfos != null){
                try {
                    sfos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

【问题讨论】:

    标签: java utf-8 jcifs


    【解决方案1】:
    content.getBytes("UTF-8")
    

    使用给定的字符集将此字符串编码为字节序列,并将结果存储到新的字节数组中。 此方法始终使用此字符集的默认替换字节数组替换格式错误的输入和不可映射的字符序列。当需要对编码过程进行更多控制时,应使用 CharsetEncoder 类。

    【讨论】:

      猜你喜欢
      • 2012-03-08
      • 2016-03-19
      • 2013-03-15
      • 2014-09-14
      • 1970-01-01
      • 2015-08-29
      • 2017-07-10
      • 2012-02-12
      • 2015-03-29
      相关资源
      最近更新 更多