nativescript:属性“ write”在类型“ NSOutputStream”上不存在。 ts(2339)

时间:2020-01-22 21:52:45

标签: ios typescript nativescript nsstream

我想念一些东西。我需要使用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的方法 谢谢

0 个答案:

没有答案