我想念一些东西。我需要使用NSOutputStream为ios编写一个文本文件。我创建文件
import { knownFolders, Folder, File } from "tns-core-modules/file-system";
const folder: Folder=<Folder>knownFolders.documents();
let outFOS: NSOutputStream;
let pathName: File;
let isFileOpen: boolean;
export class TxtFileIo{
constructor(fileName:string) {
isFileOpen = false;
try{
pathName=<File>folder.getFile(`${fileName}.txt`);
console.log(`TxtFile iOS new file ${pathName.path}`);
outFOS=<NSOutputStream> NSOutputStream.outputStreamToFileAtPathAppend(pathName.path, true)
outFOS.open();
}catch(IOex) {
console.log("TxtFile ios new TxtFile error: " +IOex);
}
isFileOpen=true;
}
并使用
关闭文件 close() {
try {
outFOS.close();
isFileOpen=false;
console.log("TxtFile iOS close file:" +pathName.name);
}
catch (IOex) {
console.log("TxtFile iOS close error: " +IOex);
}
}
文件已创建并且可见,但是,如何写入它。我收到上述错误
write(saveData:string) {
try {
console.log("TxtFile iOS write data: " +saveData);
outFOS.write(saveData,saveData.length);
}
catch (IOex) {
console.log("TxtFile iOS write error: " +IOex);
}
}
我想念什么?我以为'write'是NSStream.outputStream的方法 谢谢