JCIFS - SMBFileOutputStream 作为 UTF8
JCIFS - SMBFileOutputStream as UTF8
如何将文件写入 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();
}
}
}
content.getBytes("UTF-8")
Encodes this String into a sequence of bytes using the given charset, storing the result into a new byte array.
This method always replaces malformed-input and unmappable-character sequences with this charset's default replacement byte array. The CharsetEncoder class should be used when more control over the encoding process is required.
如何将文件写入 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();
}
}
}
content.getBytes("UTF-8")
Encodes this String into a sequence of bytes using the given charset, storing the result into a new byte array. This method always replaces malformed-input and unmappable-character sequences with this charset's default replacement byte array. The CharsetEncoder class should be used when more control over the encoding process is required.