我正在将文件从 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/