如何创建临时文件
========

可以参考如下示例：

import { fileIo, ReadOptions } from '@kit.CoreFileKit';
import { common } from '@kit.AbilityKit';
import { buffer } from '@kit.ArkTS';

@Entry
@Component
struct CreateFileDemo {
  @State message: string = 'Hello World';
  @State writeStr: string = 'write content';
  @State readStr: string = 'read content';

  build() {
    Column() {
      Text(this.message)
      Button(this.writeStr)
        .margin({ top: 15, bottom: 15 })
        .onClick(() => {
          let context = this.getUIContext().getHostContext();
          let filesDir = context!.tempDir;
          let file = fileIo.openSync(filesDir + '/test.txt', fileIo.OpenMode.READ\_WRITE | fileIo.OpenMode.CREATE);
         _ // Write a paragraph of content to a file_
          fileIo.writeSync(file.fd, 'Try to write str.');
          console.info('str has been written');
          _// close file_
          fileIo.closeSync(file);
        })
      Button(this.readStr)
        .onClick(() => {
          let context = this.getUIContext().getHostContext();
          let filesDir = context!.tempDir;
          let file = fileIo.openSync(filesDir + '/test.txt', fileIo.OpenMode.READ\_WRITE);
         _ // Read a section of content from a file_
          let arrayBuffer = new ArrayBuffer(1024);
          let readOptions: ReadOptions = {
            offset: 0,
            length: arrayBuffer.byteLength
          };
          let readLen = fileIo.readSync(file.fd, arrayBuffer, readOptions);
          let buf = buffer.from(arrayBuffer, 0, readLen);
          this.message = buf.toString();
         _ // close file_
          fileIo.closeSync(file);
        })
    }
    .height('100%')
    .width('100%')
  }
}