java - jcifs 无法将新行写入文本文件

标签 java android samba jcifs

我正在将文件从 Android 设备写入 Windows 文件夹
所有内容均完好无损 但我无法写新行

    NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null,nam,p);
    file = new SmbFile(url, auth);

    SmbFileOutputStream out = new SmbFileOutputStream(file,true);

我已经尝试过:

out.write(("next"+ "\n" + text).getBytes());               
out.write(("next"+String.format("%n") + text).getBytes());
out.write(("next"+System.getProperty("line.separator") + text).getBytes());         
out.flush();
out.close();

但似乎都不起作用,请帮忙。

最佳答案

这就是我用新行写入文件的方法

                Date now = new Date();
                String strDateFormat = "EEEE, MMMM dd, yyyy HH:mm:ss";
                SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
                String txtVal = "INFO\t" + usr + "\t" + sdf.format(now) + "\t" +count +"\t"+"Ver.1";            
                NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("XXXX", "XXXXX", "XXXXXX");
                String path = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
                SmbFile sFile = new SmbFile(path, auth);
                //SmbFileOutputStream sfos = new SmbFileOutputStream(sFile);

                SmbFileOutputStream sfos = new SmbFileOutputStream(sFile, true);                

                sfos.write((txtVal+"\r\n").getBytes());               
                sfos.close();

关于java - jcifs 无法将新行写入文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19052775/

相关文章:

java - 如何在按 10 次时禁用 jbutton

java - 如何从json中提取所有变量名称?

java - java中的计时器,速度降低

android - Jetpack 撰写 : Performance problem when element with GlideImage is clickable in LazyColumn

Android Studio 模块 gradle clean install 给出错误 com.android.volley 不存在

virtual-machine - 如何让 winexe 附加到非标准端口?

java - 根据java中的字母将按字母顺序排序的列表拆分为子列表

android - 如何使用 Qt 将文件写入 Android 设备?

centos - Samba 共享不可写 (Linux)

Nginx: "Resource temporarily unavailable"使用 Samba 共享