Encoding 如何选择SmbFileOutputStream创建的文件的编码?

Encoding 如何选择SmbFileOutputStream创建的文件的编码?,encoding,Encoding,我正在使用一种方法在本地网络中的共享文件夹中的特定路径中创建文件 public static void stringToArquivoTextoRemoto(String path, String fileName, String content, NtlmPasswordAuthentication auth) { String absolutePath = path + File.separator + fileName; try {

我正在使用一种方法在本地网络中的共享文件夹中的特定路径中创建文件

public static void stringToArquivoTextoRemoto(String path, String fileName, String content, NtlmPasswordAuthentication auth) {
            String absolutePath = path + File.separator + fileName;
            try {
                    jcifs.Config.setProperty("jcifs.smb.client.disablePlainTextPasswords", "false");
                    SmbFile smbFile = new SmbFile(absolutePath, auth);
                    SmbFileOutputStream smbFileOutputStream = new SmbFileOutputStream(smbFile);
                    smbFileOutputStream.write(content.getBytes());
                    smbFileOutputStream.close();
            } catch (MalformedURLException e) {
                    e.printStackTrace();
            } catch (SmbException e) {
                    e.printStackTrace();
            } catch (UnknownHostException e) {
                    e.printStackTrace();
            } catch (IOException e) {
                    e.printStackTrace();
            }
    }
现在,我正在尝试将编码从“UTF-8”更改为“ISO-8859-1”。 我已经试着说:

jcifs.Config.setProperty( "jcifs.encoding", "ISO-8859-1" );
但它不起作用

我发现了很多关于如何使用FileOutputStream更改编码的信息,但是使用SmbFileOutputStream我没有发现任何关于这方面的信息


选择SmbFileOutputStream创建的文件的编码需要做什么?

这将解决问题:

package fileWriting;

import java.io.IOException;

import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileOutputStream;

public class testWriting {

    public static void main(String[] args) throws IOException {
        String user = "domain;username:password";
        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(user);
        String path = "smb://shared/Projects/test.txt";
        SmbFile sFile = new SmbFile(path, auth);
        try (SmbFileOutputStream sfos = new SmbFileOutputStream(sFile)) {
            String v = "Test for file writing!";
            byte[] utf = v.getBytes("UTF-8");
            byte[] latin1 = new String(utf, "UTF-8").getBytes("ISO-8859-1");
            sfos.write(latin1,0,latin1.length );
        }
    }
}

这将解决问题:

package fileWriting;

import java.io.IOException;

import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileOutputStream;

public class testWriting {

    public static void main(String[] args) throws IOException {
        String user = "domain;username:password";
        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(user);
        String path = "smb://shared/Projects/test.txt";
        SmbFile sFile = new SmbFile(path, auth);
        try (SmbFileOutputStream sfos = new SmbFileOutputStream(sFile)) {
            String v = "Test for file writing!";
            byte[] utf = v.getBytes("UTF-8");
            byte[] latin1 = new String(utf, "UTF-8").getBytes("ISO-8859-1");
            sfos.write(latin1,0,latin1.length );
        }
    }
}