1# @ohos.fileio (File Management) 2 3The **fileio** module provides APIs for file storage and management, including basic file management, directory management, file information statistics, and stream read and write. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> - The APIs provided by this module are deprecated since API version 9. You are advised to use [@ohos.file.fs](js-apis-file-fs.md). 9 10## Modules to Import 11 12```ts 13import fileio from '@ohos.fileio'; 14``` 15 16 17## Guidelines 18 19Before using the APIs provided by this module to perform operations on a file or directory, obtain the application sandbox path of the file or directory as follows: 20 21 ```ts 22 import UIAbility from '@ohos.app.ability.UIAbility'; 23 import window from '@ohos.window'; 24 25 export default class EntryAbility extends UIAbility { 26 onWindowStageCreate(windowStage: window.WindowStage) { 27 let context = this.context; 28 let pathDir = context.filesDir; 29 } 30 } 31 ``` 32 33For details about how to obtain the application sandbox path, see [Obtaining Application File Paths](../../application-models/application-context-stage.md#obtaining-application-file-paths). 34 35 36## fileio.stat 37 38stat(path: string): Promise<Stat> 39 40Obtains file information. This API uses a promise to return the result. 41 42> **NOTE** 43> 44> This API is deprecated since API version 9. Use [fs.stat](js-apis-file-fs.md#stat) instead. 45 46**System capability**: SystemCapability.FileManagement.File.FileIO 47 48**Parameters** 49 50| Name| Type | Mandatory| Description | 51| ------ | ------ | ---- | -------------------------- | 52| path | string | Yes | Application sandbox path of the file.| 53 54**Return value** 55 56 | Type | Description | 57 | ---------------------------- | ---------- | 58 | Promise<[Stat](#stat)> | Promise used to return the file information obtained.| 59 60**Example** 61 62 ```ts 63 import { BusinessError } from '@ohos.base'; 64 let filePath = pathDir + "test.txt"; 65 fileio.stat(filePath).then((stat: fileio.Stat) => { 66 console.info("getFileInfo succeed, the size of file is " + stat.size); 67 }).catch((err: BusinessError) => { 68 console.error("getFileInfo failed with error:" + err); 69 }); 70 ``` 71 72 73## fileio.stat 74 75stat(path: string, callback: AsyncCallback<Stat>): void 76 77Obtains file information. This API uses an asynchronous callback to return the result. 78 79> **NOTE** 80> 81> This API is deprecated since API version 9. Use [fs.stat](js-apis-file-fs.md#fsstat-1) instead. 82 83**System capability**: SystemCapability.FileManagement.File.FileIO 84 85**Parameters** 86 87| Name | Type | Mandatory| Description | 88| -------- | ---------------------------------- | ---- | ------------------------------ | 89| path | string | Yes | Application sandbox path of the file. | 90| callback | AsyncCallback<[Stat](#stat)> | Yes | Callback used to return the file information obtained.| 91 92**Example** 93 94 ```ts 95 import { BusinessError } from '@ohos.base'; 96 fileio.stat(pathDir, (err: BusinessError, stat: fileio.Stat) => { 97 // Example code in Stat 98 }); 99 ``` 100 101 102## fileio.statSync 103 104statSync(path: string): Stat 105 106Obtains file information. This API returns the result synchronously. 107 108> **NOTE** 109> 110> This API is deprecated since API version 9. Use [fs.statSync](js-apis-file-fs.md#fsstatsync) instead. 111 112**System capability**: SystemCapability.FileManagement.File.FileIO 113 114**Parameters** 115 116| Name| Type | Mandatory| Description | 117| ------ | ------ | ---- | -------------------------- | 118| path | string | Yes | Application sandbox path of the file.| 119 120 121**Return value** 122 123 | Type | Description | 124 | ------------- | ---------- | 125 | [Stat](#stat) | File information obtained.| 126 127**Example** 128 129 ```ts 130 let stat = fileio.statSync(pathDir); 131 // Example code in Stat 132 ``` 133 134 135## fileio.opendir 136 137opendir(path: string): Promise<Dir> 138 139Opens a directory. This API uses a promise to return the result. 140 141> **NOTE** 142> 143> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile) instead. 144 145**System capability**: SystemCapability.FileManagement.File.FileIO 146 147**Parameters** 148 149| Name| Type | Mandatory| Description | 150| ------ | ------ | ---- | ------------------------------ | 151| path | string | Yes | Application sandbox path of the directory to open.| 152 153**Return value** 154 155 | Type | Description | 156 | -------------------------- | -------- | 157 | Promise<[Dir](#dir)> | Promise used to return the **Dir** object opened.| 158 159**Example** 160 161 ```ts 162 import { BusinessError } from '@ohos.base'; 163 let dirPath = pathDir + "/testDir"; 164 fileio.opendir(dirPath).then((dir: fileio.Dir) => { 165 console.info("opendir succeed"); 166 }).catch((err: BusinessError) => { 167 console.error("opendir failed with error:" + err); 168 }); 169 ``` 170 171 172## fileio.opendir 173 174opendir(path: string, callback: AsyncCallback<Dir>): void 175 176Opens a file directory. This API uses an asynchronous callback to return the result. 177 178> **NOTE** 179> 180> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile-1) instead. 181 182**System capability**: SystemCapability.FileManagement.File.FileIO 183 184**Parameters** 185 186| Name | Type | Mandatory| Description | 187| -------- | -------------------------------- | ---- | ------------------------------ | 188| path | string | Yes | Application sandbox path of the directory to open.| 189| callback | AsyncCallback<[Dir](#dir)> | Yes | Callback used to return the result. | 190 191**Example** 192 193 ```ts 194 import { BusinessError } from '@ohos.base'; 195 fileio.opendir(pathDir, (err: BusinessError, dir: fileio.Dir) => { 196 // Example code in Dir struct 197 // Use read/readSync/close. 198 }); 199 ``` 200 201 202## fileio.opendirSync 203 204opendirSync(path: string): Dir 205 206Opens a directory. This API returns the result synchronously. 207 208> **NOTE** 209> 210> This API is deprecated since API version 9. Use [fs.listFileSync](js-apis-file-fs.md#fslistfilesync) instead. 211 212**System capability**: SystemCapability.FileManagement.File.FileIO 213 214**Parameters** 215 216| Name| Type | Mandatory| Description | 217| ------ | ------ | ---- | ------------------------------ | 218| path | string | Yes | Application sandbox path of the directory to open.| 219 220**Return value** 221 222 | Type | Description | 223 | ----------- | -------- | 224 | [Dir](#dir) | A **Dir** instance corresponding to the directory.| 225 226**Example** 227 228 ```ts 229 let dir = fileio.opendirSync(pathDir); 230 // Example code in Dir struct 231 // Use read/readSync/close. 232 ``` 233 234 235## fileio.access 236 237access(path: string, mode?: number): Promise<void> 238 239Checks whether this process can access a file. This API uses a promise to return the result. 240 241> **NOTE** 242> 243> This API is deprecated since API version 9. Use [fs.access](js-apis-file-fs.md#fsaccess) instead. 244 245**System capability**: SystemCapability.FileManagement.File.FileIO 246 247**Parameters** 248 249| Name| Type | Mandatory| Description | 250| ------ | ------ | ---- | ------------------------------------------------------------ | 251| path | string | Yes | Application sandbox path of the file. | 252| mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.<br>The options are as follows:<br>- **0**: Check whether the file exists.<br>- **1**: Check whether the process has the execute permission on the file.<br>- **2**: Check whether the process has the write permission on the file.<br>- **4**: Check whether the process has the read permission on the file.| 253 254**Return value** 255 256 | Type | Description | 257 | ------------------- | ---------------------------- | 258 | Promise<void> | Promise that returns no value.| 259 260**Example** 261 262 ```ts 263 import { BusinessError } from '@ohos.base'; 264 let filePath = pathDir + "/test.txt"; 265 fileio.access(filePath).then(() => { 266 console.info("Access successful"); 267 }).catch((err: BusinessError) => { 268 console.error("access failed with error:" + err); 269 }); 270 ``` 271 272 273## fileio.access 274 275access(path: string, mode?: number, callback: AsyncCallback<void>): void 276 277Checks whether this process can access a file. This API uses an asynchronous callback to return the result. 278 279> **NOTE** 280> 281> This API is deprecated since API version 9. Use [fs.access](js-apis-file-fs.md#fsaccess-1) instead. 282 283**System capability**: SystemCapability.FileManagement.File.FileIO 284 285**Parameters** 286 287| Name | Type | Mandatory| Description | 288| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 289| path | string | Yes | Application sandbox path of the file. | 290| mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.<br>The options are as follows:<br>- **0**: Check whether the file exists.<br>- **1**: Check whether the process has the execute permission on the file.<br>- **2**: Check whether the process has the write permission on the file.<br>- **4**: Check whether the process has the read permission on the file.| 291| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 292 293**Example** 294 295 ```ts 296 import { BusinessError } from '@ohos.base'; 297 let filePath = pathDir + "/test.txt"; 298 fileio.access(filePath, (err: BusinessError) => { 299 // Do something. 300 }); 301 ``` 302 303 304## fileio.accessSync 305 306accessSync(path: string, mode?: number): void 307 308Checks whether this process can access a file. This API returns the result synchronously. 309 310> **NOTE** 311> 312> This API is deprecated since API version 9. Use [fs.accessSync](js-apis-file-fs.md#fsaccesssync) instead. 313 314**System capability**: SystemCapability.FileManagement.File.FileIO 315 316**Parameters** 317 318| Name| Type | Mandatory| Description | 319| ------ | ------ | ---- | ------------------------------------------------------------ | 320| path | string | Yes | Application sandbox path of the file. | 321| mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.<br>The options are as follows:<br>- **0**: Check whether the file exists.<br>- **1**: Check whether the process has the execute permission on the file.<br>- **2**: Check whether the process has the write permission on the file.<br>- **4**: Check whether the process has the read permission on the file.| 322 323**Example** 324 325 ```ts 326 import { BusinessError } from '@ohos.base'; 327 let filePath = pathDir + "/test.txt"; 328 try { 329 fileio.accessSync(filePath); 330 } catch(error) { 331 let err: BusinessError = error as BusinessError; 332 console.error("accessSync failed with error:" + err); 333 } 334 ``` 335 336 337## fileio.close<sup>7+</sup> 338 339close(fd: number): Promise<void> 340 341Closes a file. This API uses a promise to return the result. 342 343> **NOTE** 344> 345> This API is deprecated since API version 9. Use [fs.close](js-apis-file-fs.md#fsclose) instead. 346 347**System capability**: SystemCapability.FileManagement.File.FileIO 348 349**Parameters** 350 351 | Name | Type | Mandatory | Description | 352 | ---- | ------ | ---- | ------------ | 353 | fd | number | Yes | File descriptor (FD) of the file to close.| 354 355**Return value** 356 357 | Type | Description | 358 | ------------------- | ---------------------------- | 359 | Promise<void> | Promise that returns no value.| 360 361**Example** 362 363 ```ts 364 import { BusinessError } from '@ohos.base'; 365 let filePath = pathDir + "/test.txt"; 366 let fd = fileio.openSync(filePath); 367 fileio.close(fd).then(() => { 368 console.info("File closed"); 369 }).catch((err: BusinessError) => { 370 console.error("close file failed with error:" + err); 371 }); 372 ``` 373 374 375## fileio.close<sup>7+</sup> 376 377close(fd: number, callback: AsyncCallback<void>): void 378 379Closes a file. This API uses an asynchronous callback to return the result. 380 381> **NOTE** 382> 383> This API is deprecated since API version 9. Use [fs.close](js-apis-file-fs.md#fsclose-1) instead. 384 385**System capability**: SystemCapability.FileManagement.File.FileIO 386 387**Parameters** 388 389 | Name | Type | Mandatory | Description | 390 | -------- | ------------------------- | ---- | ------------ | 391 | fd | number | Yes | FD of the file to close.| 392 | callback | AsyncCallback<void> | Yes | Callback used to return the result.| 393 394**Example** 395 396 ```ts 397 import { BusinessError } from '@ohos.base'; 398 let filePath = pathDir + "/test.txt"; 399 let fd = fileio.openSync(filePath); 400 fileio.close(fd, (err: BusinessError) => { 401 // Do something. 402 }); 403 ``` 404 405 406## fileio.closeSync 407 408closeSync(fd: number): void 409 410Closes a file. This API returns the result synchronously. 411 412> **NOTE** 413> 414> This API is deprecated since API version 9. Use [fs.closeSync](js-apis-file-fs.md#fsclosesync) instead. 415 416**System capability**: SystemCapability.FileManagement.File.FileIO 417 418**Parameters** 419 420 | Name | Type | Mandatory | Description | 421 | ---- | ------ | ---- | ------------ | 422 | fd | number | Yes | FD of the file to close.| 423 424**Example** 425 426 ```ts 427 let filePath = pathDir + "/test.txt"; 428 let fd = fileio.openSync(filePath); 429 fileio.closeSync(fd); 430 ``` 431 432 433## fileio.copyFile 434 435copyFile(src: string|number, dest: string|number, mode?: number): Promise<void> 436 437Copies a file. This API uses a promise to return the result. 438 439> **NOTE** 440> 441> This API is deprecated since API version 9. Use [fs.copyFile](js-apis-file-fs.md#fscopyfile) instead. 442 443**System capability**: SystemCapability.FileManagement.File.FileIO 444 445**Parameters** 446 447 | Name | Type | Mandatory | Description | 448 | ---- | -------------------------- | ---- | ---------------------------------------- | 449 | src | string\|number | Yes | Path or FD of the file to copy. | 450 | dest | string\|number | Yes | Path or FD of the new file. | 451 | mode | number | No | Whether to overwrite the file with the same name in the destination directory. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.| 452 453**Return value** 454 455 | Type | Description | 456 | ------------------- | ---------------------------- | 457 | Promise<void> | Promise that returns no value.| 458 459**Example** 460 461 ```ts 462 import { BusinessError } from '@ohos.base'; 463 let srcPath = pathDir + "srcDir/test.txt"; 464 let dstPath = pathDir + "dstDir/test.txt"; 465 fileio.copyFile(srcPath, dstPath).then(() => { 466 console.info("File copied"); 467 }).catch((err: BusinessError) => { 468 console.error("copyFile failed with error:" + err); 469 }); 470 ``` 471 472 473## fileio.copyFile 474 475copyFile(src: string|number, dest: string|number, mode: number, callback: AsyncCallback<void>): void 476 477Copies a file. This API uses an asynchronous callback to return the result. 478 479> **NOTE** 480> 481> This API is deprecated since API version 9. Use [fs.copyFile](js-apis-file-fs.md#fscopyfile-1) instead. 482 483**System capability**: SystemCapability.FileManagement.File.FileIO 484 485**Parameters** 486 487 | Name | Type | Mandatory | Description | 488 | -------- | -------------------------- | ---- | ---------------------------------------- | 489 | src | string\|number | Yes | Path or FD of the file to copy. | 490 | dest | string\|number | Yes | Path or FD of the new file. | 491 | mode | number | No | Whether to overwrite the file with the same name in the destination directory. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.| 492 | callback | AsyncCallback<void> | Yes | Callback used to return the result. | 493 494**Example** 495 496 ```ts 497 import { BusinessError } from '@ohos.base'; 498 let srcPath = pathDir + "srcDir/test.txt"; 499 let dstPath = pathDir + "dstDir/test.txt"; 500 fileio.copyFile(srcPath, dstPath, (err: BusinessError) => { 501 // Do something. 502 }); 503 ``` 504 505 506## fileio.copyFileSync 507 508copyFileSync(src: string|number, dest: string|number, mode?: number): void 509 510Copies a file. This API returns the result synchronously. 511 512> **NOTE** 513> 514> This API is deprecated since API version 9. Use [fs.copyFileSync](js-apis-file-fs.md#fscopyfilesync) instead. 515 516**System capability**: SystemCapability.FileManagement.File.FileIO 517 518**Parameters** 519 520 | Name | Type | Mandatory | Description | 521 | ---- | -------------------------- | ---- | ---------------------------------------- | 522 | src | string\|number | Yes | Path or FD of the file to copy. | 523 | dest | string\|number | Yes | Path or FD of the new file. | 524 | mode | number | No | Whether to overwrite the file with the same name in the destination directory. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.| 525 526**Example** 527 528 ```ts 529 let srcPath = pathDir + "srcDir/test.txt"; 530 let dstPath = pathDir + "dstDir/test.txt"; 531 fileio.copyFileSync(srcPath, dstPath); 532 ``` 533 534 535## fileio.mkdir 536 537mkdir(path: string, mode?: number): Promise<void> 538 539Creates a directory. This API uses a promise to return the result. 540 541> **NOTE** 542> 543> This API is deprecated since API version 9. Use [fs.mkdir](js-apis-file-fs.md#fsmkdir) instead. 544 545**System capability**: SystemCapability.FileManagement.File.FileIO 546 547**Parameters** 548 549| Name| Type | Mandatory| Description | 550| ------ | ------ | ---- | ------------------------------------------------------------ | 551| path | string | Yes | Application sandbox path of the directory. | 552| mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.<br>- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.| 553 554**Return value** 555 556 | Type | Description | 557 | ------------------- | ---------------------------- | 558 | Promise<void> | Promise that returns no value.| 559 560**Example** 561 562 ```ts 563 import { BusinessError } from '@ohos.base'; 564 let dirPath = pathDir + '/testDir'; 565 fileio.mkdir(dirPath).then(() => { 566 console.info("Directory created"); 567 }).catch((error: BusinessError) => { 568 console.error("mkdir failed with error:" + error); 569 }); 570 ``` 571 572 573## fileio.mkdir 574 575mkdir(path: string, mode: number, callback: AsyncCallback<void>): void 576 577Creates a directory. This API uses an asynchronous callback to return the result. 578 579> **NOTE** 580> 581> This API is deprecated since API version 9. Use [fs.mkdir](js-apis-file-fs.md#fsmkdir-1) instead. 582 583**System capability**: SystemCapability.FileManagement.File.FileIO 584 585**Parameters** 586 587| Name | Type | Mandatory| Description | 588| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 589| path | string | Yes | Application sandbox path of the directory. | 590| mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.<br>- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.| 591| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 592 593**Example** 594 595 ```ts 596 import { BusinessError } from '@ohos.base'; 597 let dirPath = pathDir + '/testDir'; 598 fileio.mkdir(dirPath, (err: BusinessError) => { 599 console.info("Directory created"); 600 }); 601 ``` 602 603 604## fileio.mkdirSync 605 606mkdirSync(path: string, mode?: number): void 607 608Creates a directory. This API returns the result synchronously. 609 610> **NOTE** 611> 612> This API is deprecated since API version 9. Use [fs.mkdirSync](js-apis-file-fs.md#fsmkdirsync) instead. 613 614**System capability**: SystemCapability.FileManagement.File.FileIO 615 616**Parameters** 617 618| Name| Type | Mandatory| Description | 619| ------ | ------ | ---- | ------------------------------------------------------------ | 620| path | string | Yes | Application sandbox path of the directory. | 621| mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.<br>- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.| 622 623**Example** 624 625 ```ts 626 let dirPath = pathDir + '/testDir'; 627 fileio.mkdirSync(dirPath); 628 ``` 629 630 631## fileio.open<sup>7+</sup> 632 633open(path: string, flags?: number, mode?: number): Promise<number> 634 635Opens a file. This API uses a promise to return the result. 636 637> **NOTE** 638> 639> This API is deprecated since API version 9. Use [fs.open](js-apis-file-fs.md#fsopen) instead. 640 641**System capability**: SystemCapability.FileManagement.File.FileIO 642 643**Parameters** 644 645| Name| Type | Mandatory| Description | 646| ------ | ------ | ---- | ------------------------------------------------------------ | 647| path | string | Yes | Application sandbox path of the file. | 648| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>- **0o0**: Open the file in read-only mode.<br>- **0o1**: Open the file in write-only mode.<br>- **0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.<br>- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>- **0o200**: If **0o100** is added and the file already exists, throw an exception.<br>- **0o1000**: If the file exists and is opened in write mode, truncate the file length to 0.<br>- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>- **0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>- **0o200000**: If **path** does not point to a directory, throw an exception.<br><br/>- **0o400000**: If **path** points to a symbolic link, throw an exception.<br>- **0o4010000**: Open the file in synchronous I/O mode.| 649| mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o660**.<br>- **0o660**: The owner and user group have the read and write permissions.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.| 650 651**Return value** 652 653 | Type | Description | 654 | --------------------- | ----------- | 655 | Promise<number> | Promise used to return the FD of the opened file.| 656 657**Example** 658 659 ```ts 660 import { BusinessError } from '@ohos.base'; 661 let filePath = pathDir + "/test.txt"; 662 fileio.open(filePath, 0o1, 0o0200).then((number: number) => { 663 console.info("File opened"); 664 }).catch((err: BusinessError) => { 665 console.error("open file failed with error:" + err); 666 }); 667 ``` 668 669 670## fileio.open<sup>7+</sup> 671 672open(path: string, flags: number, mode: number, callback: AsyncCallback<number>): void 673 674Opens a file. This API uses an asynchronous callback to return the result. 675 676> **NOTE** 677> 678> This API is deprecated since API version 9. Use [fs.open](js-apis-file-fs.md#fsopen-1) instead. 679 680**System capability**: SystemCapability.FileManagement.File.FileIO 681 682**Parameters** 683 684| Name | Type | Mandatory| Description | 685| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | 686| path | string | Yes | Application sandbox path of the file. | 687| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>- **0o0**: Open the file in read-only mode.<br>- **0o1**: Open the file in write-only mode.<br>- **0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.<br>- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>- **0o200**: If **0o100** is added and the file already exists, throw an exception.<br>- **0o1000**: If the file exists and is opened in write mode, truncate the file length to 0.<br>- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>- **0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>- **0o200000**: If **path** does not point to a directory, throw an exception.<br><br/>- **0o400000**: If **path** points to a symbolic link, throw an exception.<br>- **0o4010000**: Open the file in synchronous I/O mode.| 688| mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o660**.<br>- **0o660**: The owner and user group have the read and write permissions.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.| 689| callback | AsyncCallback<number> | Yes | Callback used to return the result. | 690 691**Example** 692 693 ```ts 694 import { BusinessError } from '@ohos.base'; 695 let filePath = pathDir + "/test.txt"; 696 fileio.open(filePath, 0, (err: BusinessError, fd: number) => { 697 // Do something. 698 }); 699 ``` 700 701 702## fileio.openSync 703 704openSync(path: string, flags?: number, mode?: number): number 705 706Opens a file. This API returns the result synchronously. 707 708> **NOTE** 709> 710> This API is deprecated since API version 9. Use [fs.openSync](js-apis-file-fs.md#fsopensync) instead. 711 712**System capability**: SystemCapability.FileManagement.File.FileIO 713 714**Parameters** 715 716| Name| Type | Mandatory| Description | 717| ------ | ------ | ---- | ------------------------------------------------------------ | 718| path | string | Yes | Application sandbox path of the file. | 719| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>- **0o0**: Open the file in read-only mode.<br>- **0o1**: Open the file in write-only mode.<br>- **0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.<br>- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>- **0o200**: If **0o100** is added and the file already exists, throw an exception.<br>- **0o1000**: If the file exists and is opened in write mode, truncate the file length to 0.<br>- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>- **0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>- **0o200000**: If **path** does not point to a directory, throw an exception.<br><br/>- **0o400000**: If **path** points to a symbolic link, throw an exception.<br>- **0o4010000**: Open the file in synchronous I/O mode.| 720| mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o660**.<br>- **0o660**: The owner and user group have the read and write permissions.<br>- **0o640**: The owner has the read and write permissions, and the user group has the read permission.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.<br>The file permissions on newly created files are affected by umask, which is set as the process starts. Currently, the modification of umask is not open.| 721 722**Return value** 723 724 | Type | Description | 725 | ------ | ----------- | 726 | number | FD of the file opened.| 727 728**Example** 729 730 ```ts 731 let filePath = pathDir + "/test.txt"; 732 let fd = fileio.openSync(filePath, 0o102, 0o640); 733 ``` 734 ```ts 735 let filePath = pathDir + "/test.txt"; 736 let fd = fileio.openSync(filePath, 0o102, 0o666); 737 fileio.writeSync(fd, 'hello world'); 738 let fd1 = fileio.openSync(filePath, 0o2002); 739 fileio.writeSync(fd1, 'hello world'); 740 class Option { 741 offset: number = 0; 742 length: number = 4096; 743 position: number = 0; 744 } 745 let option = new Option(); 746 option.position = 0; 747 let buf = new ArrayBuffer(4096) 748 let num = fileio.readSync(fd1, buf, option); 749 console.info("num == " + num); 750 ``` 751 752 753## fileio.read 754 755read(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: number; position?: number; }): Promise<ReadOut> 756 757Reads data from a file. This API uses a promise to return the result. 758 759> **NOTE** 760> 761> This API is deprecated since API version 9. Use [fs.read](js-apis-file-fs.md#fsread) instead. 762 763**System capability**: SystemCapability.FileManagement.File.FileIO 764 765**Parameters** 766 767| Name | Type | Mandatory| Description | 768| ------- | ----------- | ---- | ------------------------------------------------------------ | 769| fd | number | Yes | FD of the file to read. | 770| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | 771| options | Object | No | The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. This parameter is optional. The default value is **0**.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size| 772 773**Return value** 774 775 | Type | Description | 776 | ---------------------------------- | ------ | 777 | Promise<[ReadOut](#readout)> | Promise used to return the data read.| 778 779**Example** 780 781 ```ts 782 import { BusinessError } from '@ohos.base'; 783 import buffer from '@ohos.buffer'; 784 let filePath = pathDir + "/test.txt"; 785 let fd = fileio.openSync(filePath, 0o102, 0o640); 786 let arrayBuffer = new ArrayBuffer(4096); 787 fileio.read(fd, arrayBuffer).then((readResult: fileio.ReadOut) => { 788 console.info("Read file data successfully"); 789 let buf = buffer.from(arrayBuffer, 0, readResult.bytesRead); 790 console.log(`The content of file: ${buf.toString()}`); 791 fileio.closeSync(fd); 792 }).catch((err: BusinessError) => { 793 console.error("read file data failed with error:" + err); 794 }); 795 ``` 796 797 798## fileio.read 799 800read(fd: number, buffer: ArrayBuffer, options: { offset?: number; length?: number; position?: number; }, callback: AsyncCallback<ReadOut>): void 801 802Reads data from a file. This API uses an asynchronous callback to return the result. 803 804> **NOTE** 805> 806> This API is deprecated since API version 9. Use [fs.read](js-apis-file-fs.md#fsread-1) instead. 807 808**System capability**: SystemCapability.FileManagement.File.FileIO 809 810**Parameters** 811 812 | Name | Type | Mandatory | Description | 813 | -------- | ---------------------------------------- | ---- | ---------------------------------------- | 814 | fd | number | Yes | FD of the file to read. | 815 | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | 816 | options | Object | No | The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. This parameter is optional. The default value is **0**.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size | 817 | callback | AsyncCallback<[ReadOut](#readout)> | Yes | Callback used to return the result. | 818 819**Example** 820 821 ```ts 822 import { BusinessError } from '@ohos.base'; 823 import buffer from '@ohos.buffer'; 824 let filePath = pathDir + "/test.txt"; 825 let fd = fileio.openSync(filePath, 0o102, 0o640); 826 let arrayBuffer = new ArrayBuffer(4096); 827 fileio.read(fd, arrayBuffer, (err: BusinessError, readResult: fileio.ReadOut) => { 828 if (readResult) { 829 console.info("Read file data successfully"); 830 let buf = buffer.from(arrayBuffer, 0, readResult.bytesRead); 831 console.info(`The content of file: ${buf.toString()}`); 832 } 833 fileio.closeSync(fd); 834 }); 835 ``` 836 837 838## fileio.readSync 839 840readSync(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: number; position?: number; }): number 841 842Reads data from a file. This API returns the result synchronously. 843 844> **NOTE** 845> 846> This API is deprecated since API version 9. Use [fs.readSync](js-apis-file-fs.md#fsreadsync) instead. 847 848**System capability**: SystemCapability.FileManagement.File.FileIO 849 850**Parameters** 851 852 | Name | Type | Mandatory | Description | 853 | ------- | ----------- | ---- | ---------------------------------------- | 854 | fd | number | Yes | FD of the file to read. | 855 | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | 856 | options | Object | No | The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. This parameter is optional. The default value is **0**.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size | 857 858**Return value** 859 860 | Type | Description | 861 | ------ | -------- | 862 | number | Length of the data read.| 863 864**Example** 865 866 ```ts 867 let filePath = pathDir + "/test.txt"; 868 let fd = fileio.openSync(filePath, 0o2); 869 let buf = new ArrayBuffer(4096); 870 let num = fileio.readSync(fd, buf); 871 ``` 872 873 874## fileio.rmdir<sup>7+</sup> 875 876rmdir(path: string): Promise<void> 877 878Deletes a directory. This API uses a promise to return the result. 879 880> **NOTE** 881> 882> This API is deprecated since API version 9. Use [fs.rmdir](js-apis-file-fs.md#fsrmdir) instead. 883 884**System capability**: SystemCapability.FileManagement.File.FileIO 885 886**Parameters** 887 888| Name| Type | Mandatory| Description | 889| ------ | ------ | ---- | -------------------------- | 890| path | string | Yes | Application sandbox path of the directory.| 891 892**Return value** 893 894 | Type | Description | 895 | ------------------- | ---------------------------- | 896 | Promise<void> | Promise that returns no value.| 897 898**Example** 899 900 ```ts 901 import { BusinessError } from '@ohos.base'; 902 let dirPath = pathDir + '/testDir'; 903 fileio.rmdir(dirPath).then(() => { 904 console.info("Directory deleted"); 905 }).catch((err: BusinessError) => { 906 console.error("rmdir failed with error:" + err); 907 }); 908 ``` 909 910 911## fileio.rmdir<sup>7+</sup> 912 913rmdir(path: string, callback: AsyncCallback<void>): void 914 915Deletes a directory. This API uses an asynchronous callback to return the result. 916 917> **NOTE** 918> 919> This API is deprecated since API version 9. Use [fs.rmdir](js-apis-file-fs.md#fsrmdir-1) instead. 920 921**System capability**: SystemCapability.FileManagement.File.FileIO 922 923**Parameters** 924 925| Name | Type | Mandatory| Description | 926| -------- | ------------------------- | ---- | -------------------------- | 927| path | string | Yes | Application sandbox path of the directory.| 928| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 929 930**Example** 931 932 ```ts 933 import { BusinessError } from '@ohos.base'; 934 let dirPath = pathDir + '/testDir'; 935 fileio.rmdir(dirPath, (err: BusinessError) => { 936 // Do something. 937 console.info("Directory deleted"); 938 }); 939 ``` 940 941 942## fileio.rmdirSync<sup>7+</sup> 943 944rmdirSync(path: string): void 945 946Deletes a directory. This API returns the result synchronously. 947 948> **NOTE** 949> 950> This API is deprecated since API version 9. Use [fs.rmdirSync](js-apis-file-fs.md#fsrmdirsync) instead. 951 952**System capability**: SystemCapability.FileManagement.File.FileIO 953 954**Parameters** 955 956| Name| Type | Mandatory| Description | 957| ------ | ------ | ---- | -------------------------- | 958| path | string | Yes | Application sandbox path of the directory.| 959 960**Example** 961 962 ```ts 963 let dirPath = pathDir + '/testDir'; 964 fileio.rmdirSync(dirPath); 965 ``` 966 967 968## fileio.unlink 969 970unlink(path: string): Promise<void> 971 972Deletes a file. This API uses a promise to return the result. 973 974> **NOTE** 975> 976> This API is deprecated since API version 9. Use [fs.unlink](js-apis-file-fs.md#fsunlink) instead. 977 978**System capability**: SystemCapability.FileManagement.File.FileIO 979 980**Parameters** 981 982| Name| Type | Mandatory| Description | 983| ------ | ------ | ---- | -------------------------- | 984| path | string | Yes | Application sandbox path of the file.| 985 986**Return value** 987 988 | Type | Description | 989 | ------------------- | ---------------------------- | 990 | Promise<void> | Promise that returns no value.| 991 992**Example** 993 994 ```ts 995 import { BusinessError } from '@ohos.base'; 996 let filePath = pathDir + "/test.txt"; 997 fileio.unlink(filePath).then(() => { 998 console.info("File deleted"); 999 }).catch((error: BusinessError) => { 1000 console.error("remove file failed with error:" + error); 1001 }); 1002 ``` 1003 1004 1005## fileio.unlink 1006 1007unlink(path: string, callback: AsyncCallback<void>): void 1008 1009Deletes a file. This API uses an asynchronous callback to return the result. 1010 1011> **NOTE** 1012> 1013> This API is deprecated since API version 9. Use [fs.unlink](js-apis-file-fs.md#fsunlink-1) instead. 1014 1015**System capability**: SystemCapability.FileManagement.File.FileIO 1016 1017**Parameters** 1018 1019| Name | Type | Mandatory| Description | 1020| -------- | ------------------------- | ---- | -------------------------- | 1021| path | string | Yes | Application sandbox path of the file.| 1022| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 1023 1024**Example** 1025 1026 ```ts 1027 import { BusinessError } from '@ohos.base'; 1028 let filePath = pathDir + "/test.txt"; 1029 fileio.unlink(filePath, (err: BusinessError) => { 1030 console.info("File deleted"); 1031 }); 1032 ``` 1033 1034 1035## fileio.unlinkSync 1036 1037unlinkSync(path: string): void 1038 1039Deletes a file. This API returns the result synchronously. 1040 1041> **NOTE** 1042> 1043> This API is deprecated since API version 9. Use [fs.unlinkSync](js-apis-file-fs.md#fsunlinksync) instead. 1044 1045**System capability**: SystemCapability.FileManagement.File.FileIO 1046 1047**Parameters** 1048 1049| Name| Type | Mandatory| Description | 1050| ------ | ------ | ---- | -------------------------- | 1051| path | string | Yes | Application sandbox path of the file.| 1052 1053**Example** 1054 1055 ```ts 1056 let filePath = pathDir + "/test.txt"; 1057 fileio.unlinkSync(filePath); 1058 ``` 1059 1060 1061## fileio.write 1062 1063write(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; position?: number; encoding?: string; }): Promise<number> 1064 1065Writes data into a file. This API uses a promise to return the result. 1066 1067> **NOTE** 1068> 1069> This API is deprecated since API version 9. Use [fs.write](js-apis-file-fs.md#fswrite) instead. 1070 1071**System capability**: SystemCapability.FileManagement.File.FileIO 1072 1073**Parameters** 1074 1075 | Name | Type | Mandatory | Description | 1076 | ------- | ------------------------------- | ---- | ---------------------------------------- | 1077 | fd | number | Yes | FD of the file to write. | 1078 | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | 1079 | options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to write in reference to the start address of the data. This parameter is optional. The default value is **0**.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.<br>Constraints: offset + length <= Buffer size| 1080 1081**Return value** 1082 1083 | Type | Description | 1084 | --------------------- | -------- | 1085 | Promise<number> | Promise used to return the length of the data written.| 1086 1087**Example** 1088 1089 ```ts 1090 import { BusinessError } from '@ohos.base'; 1091 let filePath = pathDir + "/test.txt"; 1092 let fd = fileio.openSync(filePath, 0o100 | 0o2, 0o666); 1093 fileio.write(fd, "hello, world").then((number: number) => { 1094 console.info("write data to file succeed and size is:" + number); 1095 }).catch((err: BusinessError) => { 1096 console.error("write data to file failed with error:" + err); 1097 }); 1098 ``` 1099 1100 1101## fileio.write 1102 1103write(fd: number, buffer: ArrayBuffer|string, options: { offset?: number; length?: number; position?: number; encoding?: string; }, callback: AsyncCallback<number>): void 1104 1105Writes data to a file. This API uses an asynchronous callback to return the result. 1106 1107> **NOTE** 1108> 1109> This API is deprecated since API version 9. Use [fs.write](js-apis-file-fs.md#fswrite-1) instead. 1110 1111**System capability**: SystemCapability.FileManagement.File.FileIO 1112 1113**Parameters** 1114 1115 | Name | Type | Mandatory | Description | 1116 | -------- | ------------------------------- | ---- | ---------------------------------------- | 1117 | fd | number | Yes | FD of the file to write. | 1118 | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | 1119 | options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to write in reference to the start address of the data. This parameter is optional. The default value is **0**.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.<br>Constraints: offset + length <= Buffer size| 1120 | callback | AsyncCallback<number> | Yes | Callback used to return the result. | 1121 1122**Example** 1123 1124 ```ts 1125 import { BusinessError } from '@ohos.base'; 1126 let filePath = pathDir + "/test.txt"; 1127 let fd = fileio.openSync(filePath, 0o100 | 0o2, 0o666); 1128 fileio.write(fd, "hello, world", (err: BusinessError, bytesWritten: number) => { 1129 if (bytesWritten) { 1130 console.info("write data to file succeed and size is:" + bytesWritten); 1131 } 1132 }); 1133 ``` 1134 1135 1136## fileio.writeSync 1137 1138writeSync(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; position?: number; encoding?: string; }): number 1139 1140Writes data to a file. This API returns the result synchronously. 1141 1142> **NOTE** 1143> 1144> This API is deprecated since API version 9. Use [fs.writeSync](js-apis-file-fs.md#fswritesync) instead. 1145 1146**System capability**: SystemCapability.FileManagement.File.FileIO 1147 1148**Parameters** 1149 1150 | Name | Type | Mandatory | Description | 1151 | ------- | ------------------------------- | ---- | ---------------------------------------- | 1152 | fd | number | Yes | FD of the file to write. | 1153 | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | 1154 | options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to write in reference to the start address of the data. This parameter is optional. The default value is **0**.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.<br>Constraints: offset + length <= Buffer size| 1155 1156**Return value** 1157 1158 | Type | Description | 1159 | ------ | -------- | 1160 | number | Length of the data written in the file.| 1161 1162**Example** 1163 1164 ```ts 1165 let filePath = pathDir + "/test.txt"; 1166 let fd = fileio.openSync(filePath, 0o100 | 0o2, 0o666); 1167 let num = fileio.writeSync(fd, "hello, world"); 1168 ``` 1169 1170 1171## fileio.hash 1172 1173hash(path: string, algorithm: string): Promise<string> 1174 1175Calculates the hash value of a file. This API uses a promise to return the result. 1176 1177> **NOTE** 1178> 1179> This API is deprecated since API version 9. Use [hash.write](js-apis-file-hash.md#hashhash) instead. 1180 1181**System capability**: SystemCapability.FileManagement.File.FileIO 1182 1183**Parameters** 1184 1185| Name | Type | Mandatory| Description | 1186| --------- | ------ | ---- | ------------------------------------------------------------ | 1187| path | string | Yes | Application sandbox path of the file. | 1188| algorithm | string | Yes | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**. **sha256** is recommended for security purposes.| 1189 1190**Return value** 1191 1192 | Type | Description | 1193 | --------------------- | -------------------------- | 1194 | Promise<string> | Promise used to return the hash value. The hash value is a hexadecimal string consisting of digits and uppercase letters.| 1195 1196**Example** 1197 1198 ```ts 1199 import { BusinessError } from '@ohos.base'; 1200 let filePath = pathDir + "/test.txt"; 1201 fileio.hash(filePath, "sha256").then((str: string) => { 1202 console.info("calculate file hash succeed:" + str); 1203 }).catch((err: BusinessError) => { 1204 console.error("calculate file hash failed with error:" + err); 1205 }); 1206 ``` 1207 1208 1209## fileio.hash 1210 1211hash(path: string, algorithm: string, callback: AsyncCallback<string>): void 1212 1213Calculates the hash value of a file. This API uses an asynchronous callback to return the result. 1214 1215> **NOTE** 1216> 1217> This API is deprecated since API version 9. Use [hash.write](js-apis-file-hash.md#hashhash-1) instead. 1218 1219**System capability**: SystemCapability.FileManagement.File.FileIO 1220 1221**Parameters** 1222 1223| Name | Type | Mandatory| Description | 1224| --------- | --------------------------- | ---- | ------------------------------------------------------------ | 1225| path | string | Yes | Application sandbox path of the file. | 1226| algorithm | string | Yes | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**. **sha256** is recommended for security purposes.| 1227| callback | AsyncCallback<string> | Yes | Callback used to return the hash value obtained. The hash value is a hexadecimal string consisting of digits and uppercase letters.| 1228 1229**Example** 1230 1231 ```ts 1232 import { BusinessError } from '@ohos.base'; 1233 let filePath = pathDir + "/test.txt"; 1234 fileio.hash(filePath, "sha256", (err: BusinessError, hashStr: string) => { 1235 if (hashStr) { 1236 console.info("calculate file hash succeed:" + hashStr); 1237 } 1238 }); 1239 ``` 1240 1241 1242## fileio.chmod<sup>7+</sup> 1243 1244chmod(path: string, mode: number): Promise<void> 1245 1246Changes file permissions. This API uses a promise to return the result. 1247 1248> **NOTE** 1249> 1250> This API is deprecated since API version 9. 1251 1252**System capability**: SystemCapability.FileManagement.File.FileIO 1253 1254**Parameters** 1255 1256| Name| Type | Mandatory| Description | 1257| ------ | ------ | ---- | ------------------------------------------------------------ | 1258| path | string | Yes | Application sandbox path of the file. | 1259| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.| 1260 1261**Return value** 1262 1263 | Type | Description | 1264 | ------------------- | ---------------------------- | 1265 | Promise<void> | Promise that returns no value.| 1266 1267**Example** 1268 1269 ```ts 1270 import { BusinessError } from '@ohos.base'; 1271 let filePath = pathDir + "/test.txt"; 1272 fileio.chmod(filePath, 0o700).then(() => { 1273 console.info("File permissions changed"); 1274 }).catch((err: BusinessError) => { 1275 console.error("chmod failed with error:" + err); 1276 }); 1277 ``` 1278 1279 1280## fileio.chmod<sup>7+</sup> 1281 1282chmod(path: string, mode: number, callback: AsyncCallback<void>): void 1283 1284Changes file permissions. This API uses an asynchronous callback to return the result. 1285 1286> **NOTE** 1287> 1288> This API is deprecated since API version 9. 1289 1290**System capability**: SystemCapability.FileManagement.File.FileIO 1291 1292**Parameters** 1293 1294| Name | Type | Mandatory| Description | 1295| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 1296| path | string | Yes | Application sandbox path of the file. | 1297| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.| 1298| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 1299 1300**Example** 1301 1302 ```ts 1303 import { BusinessError } from '@ohos.base'; 1304 let filePath = pathDir + "/test.txt"; 1305 fileio.chmod(filePath, 0o700, (err: BusinessError) => { 1306 // Do something. 1307 }); 1308 ``` 1309 1310 1311## fileio.chmodSync<sup>7+</sup> 1312 1313chmodSync(path: string, mode: number): void 1314 1315Changes file permissions. This API returns the result synchronously. 1316 1317> **NOTE** 1318> 1319> This API is deprecated since API version 9. 1320 1321**System capability**: SystemCapability.FileManagement.File.FileIO 1322 1323**Parameters** 1324 1325| Name| Type | Mandatory| Description | 1326| ------ | ------ | ---- | ------------------------------------------------------------ | 1327| path | string | Yes | Application sandbox path of the file. | 1328| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.| 1329 1330**Example** 1331 1332 ```ts 1333 let filePath = pathDir + "/test.txt"; 1334 fileio.chmodSync(filePath, 0o700); 1335 ``` 1336 1337 1338## fileio.fstat<sup>7+</sup> 1339 1340fstat(fd: number): Promise<Stat> 1341 1342Obtains file information based on an FD. This API uses a promise to return the result. 1343 1344> **NOTE** 1345> 1346> This API is deprecated since API version 9. Use [fs.stat](js-apis-file-fs.md#fsstat) instead. 1347 1348**System capability**: SystemCapability.FileManagement.File.FileIO 1349 1350**Parameters** 1351 1352 | Name | Type | Mandatory | Description | 1353 | ---- | ------ | ---- | ------------ | 1354 | fd | number | Yes | FD of the target file.| 1355 1356**Return value** 1357 1358 | Type | Description | 1359 | ---------------------------- | ---------- | 1360 | Promise<[Stat](#stat)> | Promise used to return the detailed file information obtained.| 1361 1362**Example** 1363 1364 ```ts 1365 import { BusinessError } from '@ohos.base'; 1366 let filePath = pathDir + "/test.txt"; 1367 let fd = fileio.openSync(filePath); 1368 fileio.fstat(fd).then((stat: fileio.Stat) => { 1369 console.info("fstat succeed, the size of file is " + stat.size); 1370 }).catch((err: BusinessError) => { 1371 console.error("fstat failed with error:" + err); 1372 }); 1373 ``` 1374 1375 1376## fileio.fstat<sup>7+</sup> 1377 1378fstat(fd: number, callback: AsyncCallback<Stat>): void 1379 1380Obtains file information based on an FD. This API uses an asynchronous callback to return the result. 1381 1382> **NOTE** 1383> 1384> This API is deprecated since API version 9. Use [fs.stat](js-apis-file-fs.md#fsstat-1) instead. 1385 1386**System capability**: SystemCapability.FileManagement.File.FileIO 1387 1388**Parameters** 1389 1390 | Name | Type | Mandatory | Description | 1391 | -------- | ---------------------------------- | ---- | ---------------- | 1392 | fd | number | Yes | FD of the target file. | 1393 | callback | AsyncCallback<[Stat](#stat)> | Yes | Callback used to return the file information obtained.| 1394 1395**Example** 1396 1397 ```ts 1398 import { BusinessError } from '@ohos.base'; 1399 let filePath = pathDir + "/test.txt"; 1400 let fd = fileio.openSync(filePath); 1401 fileio.fstat(fd, (err: BusinessError) => { 1402 // Do something. 1403 }); 1404 ``` 1405 1406 1407## fileio.fstatSync<sup>7+</sup> 1408 1409fstatSync(fd: number): Stat 1410 1411Obtains file status information based on an FD. This API returns the result synchronously. 1412 1413> **NOTE** 1414> 1415> This API is deprecated since API version 9. Use [fs.statSync](js-apis-file-fs.md#fsstatsync) instead. 1416 1417**System capability**: SystemCapability.FileManagement.File.FileIO 1418 1419**Parameters** 1420 1421 | Name | Type | Mandatory | Description | 1422 | ---- | ------ | ---- | ------------ | 1423 | fd | number | Yes | FD of the target file.| 1424 1425**Return value** 1426 1427 | Type | Description | 1428 | ------------- | ---------- | 1429 | [Stat](#stat) | Detailed file information obtained.| 1430 1431**Example** 1432 1433 ```ts 1434 let filePath = pathDir + "/test.txt"; 1435 let fd = fileio.openSync(filePath); 1436 let stat = fileio.fstatSync(fd); 1437 ``` 1438 1439 1440## fileio.ftruncate<sup>7+</sup> 1441 1442ftruncate(fd: number, len?: number): Promise<void> 1443 1444Truncates a file based on an FD. This API uses a promise to return the result. 1445 1446> **NOTE** 1447> 1448> This API is deprecated since API version 9. Use [fs.truncate](js-apis-file-fs.md#fstruncate) instead. 1449 1450**System capability**: SystemCapability.FileManagement.File.FileIO 1451 1452**Parameters** 1453 1454 | Name | Type | Mandatory | Description | 1455 | ---- | ------ | ---- | ---------------- | 1456 | fd | number | Yes | FD of the file to truncate. | 1457 | len | number | No | File length, in bytes, after truncation.| 1458 1459**Return value** 1460 1461 | Type | Description | 1462 | ------------------- | ---------------------------- | 1463 | Promise<void> | Promise that returns no value.| 1464 1465**Example** 1466 1467 ```ts 1468 import { BusinessError } from '@ohos.base'; 1469 let filePath = pathDir + "/test.txt"; 1470 let fd = fileio.openSync(filePath); 1471 fileio.ftruncate(fd, 5).then(() => { 1472 console.info("File truncated"); 1473 }).catch((err: BusinessError) => { 1474 console.error("truncate file failed with error:" + err); 1475 }); 1476 ``` 1477 1478 1479## fileio.ftruncate<sup>7+</sup> 1480 1481ftruncate(fd: number, len?: number, callback: AsyncCallback<void>): void 1482 1483Truncates a file based on an FD. This API uses an asynchronous callback to return the result. 1484 1485> **NOTE** 1486> 1487> This API is deprecated since API version 9. Use [fs.truncate](js-apis-file-fs.md#fstruncate-1) instead. 1488 1489**System capability**: SystemCapability.FileManagement.File.FileIO 1490 1491**Parameters** 1492 1493 | Name | Type | Mandatory | Description | 1494 | -------- | ------------------------- | ---- | ---------------- | 1495 | fd | number | Yes | FD of the file to truncate. | 1496 | len | number | No | File length, in bytes, after truncation.| 1497 | callback | AsyncCallback<void> | Yes | Callback that returns no value. | 1498 1499**Example** 1500 1501 ```ts 1502 import { BusinessError } from '@ohos.base'; 1503 let filePath = pathDir + "/test.txt"; 1504 let fd = fileio.openSync(filePath); 1505 let len = 5; 1506 fileio.ftruncate(fd, 5, (err: BusinessError) => { 1507 // Do something. 1508 }); 1509 ``` 1510 1511 1512## fileio.ftruncateSync<sup>7+</sup> 1513 1514ftruncateSync(fd: number, len?: number): void 1515 1516Truncates a file based on an FD. This API returns the result synchronously. 1517 1518> **NOTE** 1519> 1520> This API is deprecated since API version 9. Use [fs.truncateSync](js-apis-file-fs.md#fstruncatesync) instead. 1521 1522**System capability**: SystemCapability.FileManagement.File.FileIO 1523 1524**Parameters** 1525 1526 | Name | Type | Mandatory | Description | 1527 | ---- | ------ | ---- | ---------------- | 1528 | fd | number | Yes | FD of the file to truncate. | 1529 | len | number | No | File length, in bytes, after truncation.| 1530 1531**Example** 1532 1533 ```ts 1534 let filePath = pathDir + "/test.txt"; 1535 let fd = fileio.openSync(filePath); 1536 let len = 5; 1537 fileio.ftruncateSync(fd, len); 1538 ``` 1539 1540 1541## fileio.truncate<sup>7+</sup> 1542 1543truncate(path: string, len?: number): Promise<void> 1544 1545Truncates a file based on a file path. This API uses a promise to return the result. 1546 1547> **NOTE** 1548> 1549> This API is deprecated since API version 9. Use [fs.truncate](js-apis-file-fs.md#fstruncate) instead. 1550 1551**System capability**: SystemCapability.FileManagement.File.FileIO 1552 1553**Parameters** 1554 1555| Name| Type | Mandatory| Description | 1556| ------ | ------ | ---- | -------------------------------- | 1557| path | string | Yes | Application sandbox path of the file to truncate. | 1558| len | number | No | File length, in bytes, after truncation.| 1559 1560**Return value** 1561 1562 | Type | Description | 1563 | ------------------- | ---------------------------- | 1564 | Promise<void> | Promise that returns no value.| 1565 1566**Example** 1567 1568 ```ts 1569 import { BusinessError } from '@ohos.base'; 1570 let filePath = pathDir + "/test.txt"; 1571 let len = 5; 1572 fileio.truncate(filePath, len).then(() => { 1573 console.info("File truncated"); 1574 }).catch((err: BusinessError) => { 1575 console.error("truncate file failed with error:" + err); 1576 }); 1577 ``` 1578 1579 1580## fileio.truncate<sup>7+</sup> 1581 1582truncate(path: string, len?: number, callback: AsyncCallback<void>): void 1583 1584Truncates a file based on a file path. This API uses an asynchronous callback to return the result. 1585 1586> **NOTE** 1587> 1588> This API is deprecated since API version 9. Use [fs.truncate](js-apis-file-fs.md#fstruncate-1) instead. 1589 1590**System capability**: SystemCapability.FileManagement.File.FileIO 1591 1592**Parameters** 1593 1594| Name | Type | Mandatory| Description | 1595| -------- | ------------------------- | ---- | -------------------------------- | 1596| path | string | Yes | Application sandbox path of the file to truncate. | 1597| len | number | No | File length, in bytes, after truncation.| 1598| callback | AsyncCallback<void> | Yes | Callback that returns no value. | 1599 1600**Example** 1601 1602 ```ts 1603 import { BusinessError } from '@ohos.base'; 1604 let filePath = pathDir + "/test.txt"; 1605 let len = 5; 1606 fileio.truncate(filePath, len, (err: BusinessError) => { 1607 // Do something. 1608 }); 1609 ``` 1610 1611 1612## fileio.truncateSync<sup>7+</sup> 1613 1614truncateSync(path: string, len?: number): void 1615 1616Truncates a file based on a file path. This API returns the result synchronously. 1617 1618> **NOTE** 1619> 1620> This API is deprecated since API version 9. Use [fs.truncateSync](js-apis-file-fs.md#fstruncatesync) instead. 1621 1622**System capability**: SystemCapability.FileManagement.File.FileIO 1623 1624**Parameters** 1625 1626| Name| Type | Mandatory| Description | 1627| ------ | ------ | ---- | -------------------------------- | 1628| path | string | Yes | Application sandbox path of the file to truncate. | 1629| len | number | No | File length, in bytes, after truncation.| 1630 1631**Example** 1632 1633 ```ts 1634 let filePath = pathDir + "/test.txt"; 1635 let len = 5; 1636 fileio.truncateSync(filePath, len); 1637 ``` 1638 1639 1640## fileio.readText<sup>7+</sup> 1641 1642readText(filePath: string, options?: { position?: number; length?: number; encoding?: string; }): Promise<string> 1643 1644Reads the text content of a file. This API uses a promise to return the result. 1645 1646> **NOTE** 1647> 1648> This API is deprecated since API version 9. Use [fs.readText](js-apis-file-fs.md#fsreadtext) instead. 1649 1650**System capability**: SystemCapability.FileManagement.File.FileIO 1651 1652**Parameters** 1653 1654| Name | Type | Mandatory| Description | 1655| -------- | ------ | ---- | ------------------------------------------------------------ | 1656| filePath | string | Yes | Application sandbox path of the file to read. | 1657| options | Object | No | The options are as follows:<br>- **position** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length minus the offset.<br>- **encoding** (string): format of the data to be encoded.<br>It is valid only when the data is of the string type.<br>The default value is **'utf-8'**, which is the only value supported.| 1658 1659**Return value** 1660 1661 | Type | Description | 1662 | --------------------- | ---------- | 1663 | Promise<string> | Promise used to return the file content read.| 1664 1665**Example** 1666 1667 ```ts 1668 import { BusinessError } from '@ohos.base'; 1669 let filePath = pathDir + "/test.txt"; 1670 fileio.readText(filePath).then((str: string) => { 1671 console.info("readText succeed:" + str); 1672 }).catch((err: BusinessError) => { 1673 console.error("readText failed with error:" + err); 1674 }); 1675 ``` 1676 1677 1678## fileio.readText<sup>7+</sup> 1679 1680readText(filePath: string, options: { position?: number; length?: number; encoding?: string; }, callback: AsyncCallback<string>): void 1681 1682Reads the text content of a file. This API uses an asynchronous callback to return the result. 1683 1684> **NOTE** 1685> 1686> This API is deprecated since API version 9. Use [fs.readText](js-apis-file-fs.md#fsreadtext-1) instead. 1687 1688**System capability**: SystemCapability.FileManagement.File.FileIO 1689 1690**Parameters** 1691 1692| Name | Type | Mandatory| Description | 1693| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 1694| filePath | string | Yes | Application sandbox path of the file to read. | 1695| options | Object | No | The options are as follows:<br>- **position** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length minus the offset.<br>- **encoding**: format of the data to be encoded. The default value is **'utf-8'**, which is the only value supported.| 1696| callback | AsyncCallback<string> | Yes | Callback used to return the content read. | 1697 1698**Example** 1699 1700 ```ts 1701 import { BusinessError } from '@ohos.base'; 1702 let filePath = pathDir + "/test.txt"; 1703 class Option { 1704 length: number = 4096; 1705 position: number = 0; 1706 encoding: string = 'utf-8'; 1707 } 1708 let option = new Option(); 1709 option.position = 1; 1710 option.encoding = 'utf-8'; 1711 fileio.readText(filePath, option, (err: BusinessError, str: string) => { 1712 // Do something. 1713 }); 1714 ``` 1715 1716 1717## fileio.readTextSync<sup>7+</sup> 1718 1719readTextSync(filePath: string, options?: { position?: number; length?: number; encoding?: string; }): string 1720 1721Reads the text of a file. This API returns the result synchronously. 1722 1723> **NOTE** 1724> 1725> This API is deprecated since API version 9. Use [fs.readTextSync](js-apis-file-fs.md#fsreadtextsync) instead. 1726 1727**System capability**: SystemCapability.FileManagement.File.FileIO 1728 1729**Parameters** 1730 1731| Name | Type | Mandatory| Description | 1732| -------- | ------ | ---- | ------------------------------------------------------------ | 1733| filePath | string | Yes | Application sandbox path of the file to read. | 1734| options | Object | No | The options are as follows:<br>- **position** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length minus the offset.<br>- **encoding** (string): format of the data to be encoded.<br>It is valid only when the data is of the string type.<br>The default value is **'utf-8'**, which is the only value supported.| 1735 1736**Return value** 1737 1738 | Type | Description | 1739 | ------ | -------------------- | 1740 | string | File content read.| 1741 1742**Example** 1743 1744 ```ts 1745 let filePath = pathDir + "/test.txt"; 1746 class Option { 1747 length: number = 4096; 1748 position: number = 0; 1749 encoding: string = 'utf-8'; 1750 } 1751 let option = new Option(); 1752 option.position = 1; 1753 option.length = 3; 1754 let str = fileio.readTextSync(filePath, option); 1755 ``` 1756 1757 1758## fileio.lstat<sup>7+</sup> 1759 1760lstat(path: string): Promise<Stat> 1761 1762Obtains information about a symbolic link that is used to refer to a file or directory. This API uses a promise to return the result. 1763 1764> **NOTE** 1765> 1766> This API is deprecated since API version 9. Use [fs.lstat](js-apis-file-fs.md#fslstat) instead. 1767 1768**System capability**: SystemCapability.FileManagement.File.FileIO 1769 1770**Parameters** 1771 1772| Name| Type | Mandatory| Description | 1773| ------ | ------ | ---- | -------------------------------------- | 1774| path | string | Yes | Application sandbox path of the target file.| 1775 1776**Return value** 1777 1778 | Type | Description | 1779 | ---------------------------- | ---------- | 1780 | Promise<[Stat](#stat)> | Promise used to return the symbolic link information obtained. For details, see **stat**.| 1781 1782**Example** 1783 1784 ```ts 1785 import { BusinessError } from '@ohos.base'; 1786 let filePath = pathDir + "/test.txt"; 1787 fileio.lstat(filePath).then((stat: fileio.Stat) => { 1788 console.info("get link status succeed, the size of file is" + stat.size); 1789 }).catch((err: BusinessError) => { 1790 console.error("get link status failed with error:" + err); 1791 }); 1792 ``` 1793 1794 1795## fileio.lstat<sup>7+</sup> 1796 1797lstat(path: string, callback: AsyncCallback<Stat>): void 1798 1799Obtains information about a symbolic link that is used to refer to a file or directory. This API uses an asynchronous callback to return the result. 1800 1801> **NOTE** 1802> 1803> This API is deprecated since API version 9. Use [fs.lstat](js-apis-file-fs.md#fslstat-1) instead. 1804 1805**System capability**: SystemCapability.FileManagement.File.FileIO 1806 1807**Parameters** 1808 1809| Name | Type | Mandatory| Description | 1810| -------- | ---------------------------------- | ---- | -------------------------------------- | 1811| path | string | Yes | Application sandbox path of the target file.| 1812| callback | AsyncCallback<[Stat](#stat)> | Yes | Callback used to return the symbolic link information obtained. | 1813 1814**Example** 1815 1816 ```ts 1817 import { BusinessError } from '@ohos.base'; 1818 let filePath = pathDir + "/test.txt"; 1819 fileio.lstat(filePath, (err: BusinessError, stat: fileio.Stat) => { 1820 // Do something. 1821 }); 1822 ``` 1823 1824 1825## fileio.lstatSync<sup>7+</sup> 1826 1827lstatSync(path: string): Stat 1828 1829Obtains information about a symbolic link that is used to refer to a file or directory. This API returns the result synchronously. 1830 1831> **NOTE** 1832> 1833> This API is deprecated since API version 9. Use [fs.lstatSync](js-apis-file-fs.md#fslstatsync) instead. 1834 1835**System capability**: SystemCapability.FileManagement.File.FileIO 1836 1837**Parameters** 1838 1839| Name| Type | Mandatory| Description | 1840| ------ | ------ | ---- | -------------------------------------- | 1841| path | string | Yes | Application sandbox path of the target file.| 1842 1843**Return value** 1844 1845 | Type | Description | 1846 | ------------- | ---------- | 1847 | [Stat](#stat) | File information obtained.| 1848 1849**Example** 1850 1851 ```ts 1852 let filePath = pathDir + "/test.txt"; 1853 let stat = fileio.lstatSync(filePath); 1854 ``` 1855 1856 1857## fileio.rename<sup>7+</sup> 1858 1859rename(oldPath: string, newPath: string): Promise<void> 1860 1861Renames a file. This API uses a promise to return the result. 1862 1863> **NOTE** 1864> 1865> This API is deprecated since API version 9. Use [fs.rename](js-apis-file-fs.md#fsrename) instead. 1866 1867**System capability**: SystemCapability.FileManagement.File.FileIO 1868 1869**Parameters** 1870 1871| Name | Type | Mandatory| Description | 1872| ------- | ------ | ---- | ---------------------------- | 1873| oldPath | string | Yes | Application sandbox path of the file to rename.| 1874| newPath | string | Yes | Application sandbox path of the file renamed. | 1875 1876**Return value** 1877 1878 | Type | Description | 1879 | ------------------- | ---------------------------- | 1880 | Promise<void> | Promise that returns no value.| 1881 1882**Example** 1883 1884 ```ts 1885 import { BusinessError } from '@ohos.base'; 1886 let srcFile = pathDir + "/test.txt"; 1887 let dstFile = pathDir + '/new.txt'; 1888 fileio.rename(srcFile, dstFile).then(() => { 1889 console.info("File renamed"); 1890 }).catch((err: BusinessError) => { 1891 console.error("rename failed with error:" + err); 1892 }); 1893 ``` 1894 1895 1896## fileio.rename<sup>7+</sup> 1897 1898rename(oldPath: string, newPath: string, callback: AsyncCallback<void>): void 1899 1900Renames a file. This API uses an asynchronous callback to return the result. 1901 1902> **NOTE** 1903> 1904> This API is deprecated since API version 9. Use [fs.rename](js-apis-file-fs.md#fsrename-1) instead. 1905 1906**System capability**: SystemCapability.FileManagement.File.FileIO 1907 1908**Parameters** 1909 1910| Name | Type | Mandatory| Description | 1911| -------- | ------------------------- | ---- | ---------------------------- | 1912| oldPath | string | Yes | Application sandbox path of the file to rename.| 1913| newPath | string | Yes | Application sandbox path of the file renamed. | 1914| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 1915 1916**Example** 1917 1918 ```ts 1919 import { BusinessError } from '@ohos.base'; 1920 let srcFile = pathDir + "/test.txt"; 1921 let dstFile = pathDir + '/new.txt'; 1922 fileio.rename(srcFile, dstFile, (err: BusinessError) => { 1923 }); 1924 ``` 1925 1926## fileio.renameSync<sup>7+</sup> 1927 1928renameSync(oldPath: string, newPath: string): void 1929 1930Renames a file. This API returns the result synchronously. 1931 1932> **NOTE** 1933> 1934> This API is deprecated since API version 9. Use [fs.renameSync](js-apis-file-fs.md#fsrenamesync) instead. 1935 1936**System capability**: SystemCapability.FileManagement.File.FileIO 1937 1938**Parameters** 1939 1940| Name | Type | Mandatory| Description | 1941| ------- | ------ | ---- | ---------------------------- | 1942| oldPath | string | Yes | Application sandbox path of the file to rename.| 1943| newPath | string | Yes | Application sandbox path of the file renamed. | 1944 1945**Example** 1946 1947 ```ts 1948 let srcFile = pathDir + "/test.txt"; 1949 let dstFile = pathDir + '/new.txt'; 1950 fileio.renameSync(srcFile, dstFile); 1951 ``` 1952 1953 1954## fileio.fsync<sup>7+</sup> 1955 1956fsync(fd: number): Promise<void> 1957 1958Synchronizes a file. This API uses a promise to return the result. 1959 1960> **NOTE** 1961> 1962> This API is deprecated since API version 9. Use [fs.fsync](js-apis-file-fs.md#fsfsync) instead. 1963 1964**System capability**: SystemCapability.FileManagement.File.FileIO 1965 1966**Parameters** 1967 1968 | Name | Type | Mandatory | Description | 1969 | ---- | ------ | ---- | ------------ | 1970 | fd | number | Yes | FD of the file to synchronize.| 1971 1972**Return value** 1973 1974 | Type | Description | 1975 | ------------------- | ---------------------------- | 1976 | Promise<void> | Promise that returns no value.| 1977 1978**Example** 1979 1980 ```ts 1981 import { BusinessError } from '@ohos.base'; 1982 let filePath = pathDir + "/test.txt"; 1983 let fd = fileio.openSync(filePath); 1984 fileio.fsync(fd).then(() => { 1985 console.info("Data flushed"); 1986 }).catch((err: BusinessError) => { 1987 console.error("sync data failed with error:" + err); 1988 }); 1989 ``` 1990 1991 1992## fileio.fsync<sup>7+</sup> 1993 1994fsync(fd: number, callback: AsyncCallback<void>): void 1995 1996Synchronizes a file. This API uses an asynchronous callback to return the result. 1997 1998> **NOTE** 1999> 2000> This API is deprecated since API version 9. Use [fs.fsync](js-apis-file-fs.md#fsfsync-1) instead. 2001 2002**System capability**: SystemCapability.FileManagement.File.FileIO 2003 2004**Parameters** 2005 2006 | Name | Type | Mandatory | Description | 2007 | -------- | ------------------------- | ---- | --------------- | 2008 | fd | number | Yes | FD of the file to synchronize. | 2009 | Callback | AsyncCallback<void> | Yes | Callback used to return the result.| 2010 2011**Example** 2012 2013 ```ts 2014 import { BusinessError } from '@ohos.base'; 2015 let filePath = pathDir + "/test.txt"; 2016 let fd = fileio.openSync(filePath); 2017 fileio.fsync(fd, (err: BusinessError) => { 2018 // Do something. 2019 }); 2020 ``` 2021 2022 2023## fileio.fsyncSync<sup>7+</sup> 2024 2025fsyncSync(fd: number): void 2026 2027Synchronizes a file. This API returns the result synchronously. 2028 2029> **NOTE** 2030> 2031> This API is deprecated since API version 9. Use [fs.fsyncSync](js-apis-file-fs.md#fsfsyncsync) instead. 2032 2033**System capability**: SystemCapability.FileManagement.File.FileIO 2034 2035**Parameters** 2036 2037 | Name | Type | Mandatory | Description | 2038 | ---- | ------ | ---- | ------------ | 2039 | fd | number | Yes | FD of the file to synchronize.| 2040 2041**Example** 2042 2043 ```ts 2044 let filePath = pathDir + "/test.txt"; 2045 let fd = fileio.openSync(filePath); 2046 fileio.fsyncSync(fd); 2047 ``` 2048 2049 2050## fileio.fdatasync<sup>7+</sup> 2051 2052fdatasync(fd: number): Promise<void> 2053 2054Synchronizes the data of a file. This API uses a promise to return the result. **fdatasync()** is similar to **fsync()**, but does not flush modified metadata unless that metadata is needed. 2055 2056> **NOTE** 2057> 2058> This API is deprecated since API version 9. Use [fs.fdatasync](js-apis-file-fs.md#fsfdatasync) instead. 2059 2060**System capability**: SystemCapability.FileManagement.File.FileIO 2061 2062**Parameters** 2063 2064 | Name | Type | Mandatory | Description | 2065 | ---- | ------ | ---- | ------------ | 2066 | fd | number | Yes | FD of the file to synchronize.| 2067 2068**Return value** 2069 2070 | Type | Description | 2071 | ------------------- | ---------------------------- | 2072 | Promise<void> | Promise that returns no value.| 2073 2074**Example** 2075 2076 ```ts 2077 import { BusinessError } from '@ohos.base'; 2078 let filePath = pathDir + "/test.txt"; 2079 let fd = fileio.openSync(filePath); 2080 fileio.fdatasync(fd).then(() => { 2081 console.info("Data flushed"); 2082 }).catch((err: BusinessError) => { 2083 console.error("sync data failed with error:" + err); 2084 }); 2085 ``` 2086 2087 2088## fileio.fdatasync<sup>7+</sup> 2089 2090fdatasync(fd: number, callback: AsyncCallback<void>): void 2091 2092Synchronizes the data of a file. This API uses an asynchronous callback to return the result. **fdatasync()** is similar to **fsync()**, but does not flush modified metadata unless that metadata is needed. 2093 2094> **NOTE** 2095> 2096> This API is deprecated since API version 9. Use [fs.fdatasync](js-apis-file-fs.md#fsfdatasync-1) instead. 2097 2098**System capability**: SystemCapability.FileManagement.File.FileIO 2099 2100**Parameters** 2101 2102 | Name | Type | Mandatory | Description | 2103 | -------- | ------------------------------- | ---- | ----------------- | 2104 | fd | number | Yes | FD of the file to synchronize. | 2105 | callback | AsyncCallback<void> | Yes | Callback used to return the result.| 2106 2107**Example** 2108 2109 ```ts 2110 import { BusinessError } from '@ohos.base'; 2111 let filePath = pathDir + "/test.txt"; 2112 let fd = fileio.openSync(filePath); 2113 fileio.fdatasync (fd, (err: BusinessError) => { 2114 // Do something. 2115 }); 2116 ``` 2117 2118 2119## fileio.fdatasyncSync<sup>7+</sup> 2120 2121fdatasyncSync(fd: number): void 2122 2123Synchronizes the data of a file. This API returns the result synchronously. **fdatasync()** is similar to **fsync()**, but does not flush modified metadata unless that metadata is needed. 2124 2125> **NOTE** 2126> 2127> This API is deprecated since API version 9. Use [fs.fdatasyncSync](js-apis-file-fs.md#fsfdatasyncsync) instead. 2128 2129**System capability**: SystemCapability.FileManagement.File.FileIO 2130 2131**Parameters** 2132 2133 | Name | Type | Mandatory | Description | 2134 | ---- | ------ | ---- | ------------ | 2135 | fd | number | Yes | FD of the file to synchronize.| 2136 2137**Example** 2138 2139 ```ts 2140 let filePath = pathDir + "/test.txt"; 2141 let fd = fileio.openSync(filePath); 2142 let stat = fileio.fdatasyncSync(fd); 2143 ``` 2144 2145 2146## fileio.symlink<sup>7+</sup> 2147 2148symlink(target: string, srcPath: string): Promise<void> 2149 2150Creates a symbolic link based on a file path. This API uses a promise to return the result. 2151 2152> **NOTE** 2153> 2154> This API is deprecated since API version 9. Use [fs.symlink](js-apis-file-fs.md#fssymlink) instead. 2155 2156**System capability**: SystemCapability.FileManagement.File.FileIO 2157 2158**Parameters** 2159 2160| Name | Type | Mandatory| Description | 2161| ------- | ------ | ---- | ---------------------------- | 2162| target | string | Yes | Application sandbox path of the target file. | 2163| srcPath | string | Yes | Application sandbox path of the symbolic link.| 2164 2165**Return value** 2166 2167 | Type | Description | 2168 | ------------------- | ---------------------------- | 2169 | Promise<void> | Promise that returns no value.| 2170 2171**Example** 2172 2173 ```ts 2174 import { BusinessError } from '@ohos.base'; 2175 let srcFile = pathDir + "/test.txt"; 2176 let dstFile = pathDir + '/test'; 2177 fileio.symlink(srcFile, dstFile).then(() => { 2178 console.info("Symbolic link created"); 2179 }).catch((err: BusinessError) => { 2180 console.error("symlink failed with error:" + err); 2181 }); 2182 ``` 2183 2184 2185## fileio.symlink<sup>7+</sup> 2186 2187symlink(target: string, srcPath: string, callback: AsyncCallback<void>): void 2188 2189Creates a symbolic link based on a file path. This API uses an asynchronous callback to return the result. 2190 2191> **NOTE** 2192> 2193> This API is deprecated since API version 9. Use [fs.symlink](js-apis-file-fs.md#fssymlink-1) instead. 2194 2195**System capability**: SystemCapability.FileManagement.File.FileIO 2196 2197**Parameters** 2198 2199| Name | Type | Mandatory| Description | 2200| -------- | ------------------------- | ---- | -------------------------------- | 2201| target | string | Yes | Application sandbox path of the target file. | 2202| srcPath | string | Yes | Application sandbox path of the symbolic link. | 2203| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 2204 2205**Example** 2206 2207 ```ts 2208 import { BusinessError } from '@ohos.base'; 2209 let srcFile = pathDir + "/test.txt"; 2210 let dstFile = pathDir + '/test'; 2211 fileio.symlink(srcFile, dstFile, (err: BusinessError) => { 2212 // Do something. 2213 }); 2214 ``` 2215 2216 2217## fileio.symlinkSync<sup>7+</sup> 2218 2219symlinkSync(target: string, srcPath: string): void 2220 2221Creates a symbolic link based on a file path. This API returns the result synchronously. 2222 2223> **NOTE** 2224> 2225> This API is deprecated since API version 9. Use [fs.symlinkSync](js-apis-file-fs.md#fssymlinksync) instead. 2226 2227**System capability**: SystemCapability.FileManagement.File.FileIO 2228 2229**Parameters** 2230 2231| Name | Type | Mandatory| Description | 2232| ------- | ------ | ---- | ---------------------------- | 2233| target | string | Yes | Application sandbox path of the target file. | 2234| srcPath | string | Yes | Application sandbox path of the symbolic link.| 2235 2236**Example** 2237 2238 ```ts 2239 let srcFile = pathDir + "/test.txt"; 2240 let dstFile = pathDir + '/test'; 2241 fileio.symlinkSync(srcFile, dstFile); 2242 ``` 2243 2244 2245## fileio.chown<sup>7+</sup> 2246 2247chown(path: string, uid: number, gid: number): Promise<void> 2248 2249Changes the file owner based on a file path. This API uses a promise to return the result. 2250 2251> **NOTE** 2252> 2253> This API is deprecated since API version 9. 2254 2255**System capability**: SystemCapability.FileManagement.File.FileIO 2256 2257**Parameters** 2258 2259| Name| Type | Mandatory| Description | 2260| ------ | ------ | ---- | -------------------------- | 2261| path | string | Yes | Application sandbox path of the file.| 2262| uid | number | Yes | New user ID (UID). | 2263| gid | number | Yes | New group ID (GID). | 2264 2265**Return value** 2266 2267 | Type | Description | 2268 | ------------------- | ---------------------------- | 2269 | Promise<void> | Promise that returns no value.| 2270 2271**Example** 2272 2273 ```ts 2274 import { BusinessError } from '@ohos.base'; 2275 let filePath = pathDir + "/test.txt"; 2276 let stat = fileio.statSync(filePath); 2277 fileio.chown(filePath, stat.uid, stat.gid).then(() => { 2278 console.info("File owner changed"); 2279 }).catch((err: BusinessError) => { 2280 console.error("chown failed with error:" + err); 2281 }); 2282 ``` 2283 2284 2285## fileio.chown<sup>7+</sup> 2286 2287chown(path: string, uid: number, gid: number, callback: AsyncCallback<void>): void 2288 2289Changes the file owner based on a file path. This API uses an asynchronous callback to return the result. 2290 2291> **NOTE** 2292> 2293> This API is deprecated since API version 9. 2294 2295**System capability**: SystemCapability.FileManagement.File.FileIO 2296 2297**Parameters** 2298 2299| Name | Type | Mandatory| Description | 2300| -------- | ------------------------- | ---- | ------------------------------ | 2301| path | string | Yes | Application sandbox path of the file. | 2302| uid | number | Yes | New UID. | 2303| gid | number | Yes | New GID. | 2304| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 2305 2306**Example** 2307 2308 ```ts 2309 import { BusinessError } from '@ohos.base'; 2310 let filePath = pathDir + "/test.txt"; 2311 let stat = fileio.statSync(filePath) 2312 fileio.chown(filePath, stat.uid, stat.gid, (err: BusinessError) => { 2313 // Do something. 2314 }); 2315 ``` 2316 2317## fileio.chownSync<sup>7+</sup> 2318 2319chownSync(path: string, uid: number, gid: number): void 2320 2321Changes the file owner based on its path. This API returns the result synchronously. 2322 2323> **NOTE** 2324> 2325> This API is deprecated since API version 9. 2326 2327**System capability**: SystemCapability.FileManagement.File.FileIO 2328 2329**Parameters** 2330 2331| Name| Type | Mandatory| Description | 2332| ------ | ------ | ---- | -------------------------- | 2333| path | string | Yes | Application sandbox path of the file.| 2334| uid | number | Yes | New UID. | 2335| gid | number | Yes | New GID. | 2336 2337**Example** 2338 2339 ```ts 2340 let filePath = pathDir + "/test.txt"; 2341 let stat = fileio.statSync(filePath) 2342 fileio.chownSync(filePath, stat.uid, stat.gid); 2343 ``` 2344 2345 2346## fileio.mkdtemp<sup>7+</sup> 2347 2348mkdtemp(prefix: string): Promise<string> 2349 2350Creates a temporary directory. The folder name is created by replacing a string (specified by **prefix**) with six randomly generated characters. This API uses a promise to return the result. 2351 2352> **NOTE** 2353> 2354> This API is deprecated since API version 9. Use [fs.mkdtemp](js-apis-file-fs.md#fsmkdtemp) instead. 2355 2356**System capability**: SystemCapability.FileManagement.File.FileIO 2357 2358**Parameters** 2359 2360 | Name | Type | Mandatory | Description | 2361 | ------ | ------ | ---- | --------------------------- | 2362 | prefix | string | Yes | String to be replaced with six randomly generated characters to create a unique temporary directory.| 2363 2364**Return value** 2365 2366 | Type | Description | 2367 | --------------------- | ---------- | 2368 | Promise<string> | Promise used to return the directory created.| 2369 2370**Example** 2371 2372 ```ts 2373 import { BusinessError } from '@ohos.base'; 2374 fileio.mkdtemp(pathDir + "/XXXXXX").then((pathDir: string) => { 2375 console.info("mkdtemp succeed:" + pathDir); 2376 }).catch((err: BusinessError) => { 2377 console.error("mkdtemp failed with error:" + err); 2378 }); 2379 ``` 2380 2381 2382## fileio.mkdtemp<sup>7+</sup> 2383 2384mkdtemp(prefix: string, callback: AsyncCallback<string>): void 2385 2386Creates a temporary directory. The folder name is created by replacing a string (specified by **prefix**) with six randomly generated characters. This API uses an asynchronous callback to return the result. 2387 2388> **NOTE** 2389> 2390> This API is deprecated since API version 9. Use [fs.mkdtemp](js-apis-file-fs.md#fsmkdtemp-1) instead. 2391 2392**System capability**: SystemCapability.FileManagement.File.FileIO 2393 2394**Parameters** 2395 2396 | Name | Type | Mandatory | Description | 2397 | -------- | --------------------------- | ---- | --------------------------- | 2398 | prefix | string | Yes | String to be replaced with six randomly generated characters to create a unique temporary directory.| 2399 | callback | AsyncCallback<string> | Yes | Callback used to return the result. | 2400 2401**Example** 2402 2403 ```ts 2404 import { BusinessError } from '@ohos.base'; 2405 fileio.mkdtemp(pathDir + "/XXXXXX", (err: BusinessError, res: string) => { 2406 // Do something. 2407 }); 2408 ``` 2409 2410 2411## fileio.mkdtempSync<sup>7+</sup> 2412 2413mkdtempSync(prefix: string): string 2414 2415Creates a temporary directory. The folder name is created by replacing a string (specified by **prefix**) with six randomly generated characters. This API returns the result synchronously. 2416 2417> **NOTE** 2418> 2419> This API is deprecated since API version 9. Use [fs.mkdtempSync](js-apis-file-fs.md#fsmkdtempsync) instead. 2420 2421**System capability**: SystemCapability.FileManagement.File.FileIO 2422 2423**Parameters** 2424 2425 | Name | Type | Mandatory | Description | 2426 | ------ | ------ | ---- | --------------------------- | 2427 | prefix | string | Yes | String to be replaced with six randomly generated characters to create a unique temporary directory.| 2428 2429**Return value** 2430 2431 | Type | Description | 2432 | ------ | ---------- | 2433 | string | Unique path generated.| 2434 2435**Example** 2436 2437 ```ts 2438 let res = fileio.mkdtempSync(pathDir + "/XXXXXX"); 2439 ``` 2440 2441 2442## fileio.fchmod<sup>7+</sup> 2443 2444fchmod(fd: number, mode: number): Promise<void> 2445 2446Changes file permissions based on an FD. This API uses a promise to return the result. 2447 2448> **NOTE** 2449> 2450> This API is deprecated since API version 9. 2451 2452**System capability**: SystemCapability.FileManagement.File.FileIO 2453 2454**Parameters** 2455 2456 | Name | Type | Mandatory | Description | 2457 | ---- | ------ | ---- | ---------------------------------------- | 2458 | fd | number | Yes | FD of the target file. | 2459 | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.| 2460 2461**Return value** 2462 2463 | Type | Description | 2464 | ------------------- | ---------------------------- | 2465 | Promise<void> | Promise that returns no value.| 2466 2467**Example** 2468 2469 ```ts 2470 import { BusinessError } from '@ohos.base'; 2471 let filePath = pathDir + "/test.txt"; 2472 let fd = fileio.openSync(filePath); 2473 let mode: number = 0o700; 2474 fileio.fchmod(fd, mode).then(() => { 2475 console.info("File permissions changed"); 2476 }).catch((err: BusinessError) => { 2477 console.error("chmod failed with error:" + err); 2478 }); 2479 ``` 2480 2481 2482## fileio.fchmod<sup>7+</sup> 2483 2484fchmod(fd: number, mode: number, callback: AsyncCallback<void>): void 2485 2486Changes file permissions based on an FD. This API uses an asynchronous callback to return the result. 2487 2488> **NOTE** 2489> 2490> This API is deprecated since API version 9. 2491 2492**System capability**: SystemCapability.FileManagement.File.FileIO 2493 2494**Parameters** 2495 2496 | Name | Type | Mandatory | Description | 2497 | -------- | ------------------------------- | ---- | ---------------------------------------- | 2498 | fd | number | Yes | FD of the target file. | 2499 | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.| 2500 | callback | AsyncCallback<void> | Yes | Callback used to return the result. | 2501 2502**Example** 2503 2504 ```ts 2505 import { BusinessError } from '@ohos.base'; 2506 let filePath = pathDir + "/test.txt"; 2507 let fd = fileio.openSync(filePath); 2508 let mode: number = 0o700; 2509 fileio.fchmod(fd, mode, (err: BusinessError) => { 2510 // Do something. 2511 }); 2512 ``` 2513 2514 2515## fileio.fchmodSync<sup>7+</sup> 2516 2517fchmodSync(fd: number, mode: number): void 2518 2519Changes the file permissions based on an FD. This API returns the result synchronously. 2520 2521> **NOTE** 2522> 2523> This API is deprecated since API version 9. 2524 2525**System capability**: SystemCapability.FileManagement.File.FileIO 2526 2527**Parameters** 2528 2529 | Name | Type | Mandatory | Description | 2530 | ---- | ------ | ---- | ---------------------------------------- | 2531 | fd | number | Yes | FD of the target file. | 2532 | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.| 2533 2534**Example** 2535 2536 ```ts 2537 let filePath = pathDir + "/test.txt"; 2538 let fd = fileio.openSync(filePath); 2539 let mode: number = 0o700; 2540 fileio.fchmodSync(fd, mode); 2541 ``` 2542 2543 2544## fileio.createStream<sup>7+</sup> 2545 2546createStream(path: string, mode: string): Promise<Stream> 2547 2548Creates a stream based on a file path. This API uses a promise to return the result. 2549 2550> **NOTE** 2551> 2552> This API is deprecated since API version 9. Use [fs.createStream](js-apis-file-fs.md#fscreatestream) instead. 2553 2554**System capability**: SystemCapability.FileManagement.File.FileIO 2555 2556**Parameters** 2557 2558| Name| Type | Mandatory| Description | 2559| ------ | ------ | ---- | ------------------------------------------------------------ | 2560| path | string | Yes | Application sandbox path of the file. | 2561| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| 2562 2563**Return value** 2564 2565 | Type | Description | 2566 | --------------------------------- | --------- | 2567 | Promise<[Stream](#stream)> | Promise used to return the stream opened.| 2568 2569**Example** 2570 2571 ```ts 2572 import { BusinessError } from '@ohos.base'; 2573 let filePath = pathDir + "/test.txt"; 2574 fileio.createStream(filePath, "r+").then((stream: fileio.Stream) => { 2575 console.info("Stream created"); 2576 }).catch((err: BusinessError) => { 2577 console.error("createStream failed with error:" + err); 2578 }); 2579 ``` 2580 2581 2582## fileio.createStream<sup>7+</sup> 2583 2584createStream(path: string, mode: string, callback: AsyncCallback<Stream>): void 2585 2586Creates a stream based on a file path. This API uses an asynchronous callback to return the result. 2587 2588> **NOTE** 2589> 2590> This API is deprecated since API version 9. Use [fs.createStream](js-apis-file-fs.md#fscreatestream-1) instead. 2591 2592**System capability**: SystemCapability.FileManagement.File.FileIO 2593 2594**Parameters** 2595 2596| Name | Type | Mandatory| Description | 2597| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 2598| path | string | Yes | Application sandbox path of the file. | 2599| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| 2600| callback | AsyncCallback<[Stream](#stream)> | Yes | Callback used to return the result. | 2601 2602**Example** 2603 2604 ```ts 2605 import { BusinessError } from '@ohos.base'; 2606 let filePath = pathDir + "/test.txt"; 2607 fileio.createStream(filePath, "r+", (err: BusinessError, stream: fileio.Stream) => { 2608 // Do something. 2609 }); 2610 ``` 2611 2612 2613## fileio.createStreamSync<sup>7+</sup> 2614 2615createStreamSync(path: string, mode: string): Stream 2616 2617Creates a stream based on a file path. This API returns the result synchronously. 2618 2619> **NOTE** 2620> 2621> This API is deprecated since API version 9. Use [fs.createStreamSync](js-apis-file-fs.md#fscreatestreamsync) instead. 2622 2623**System capability**: SystemCapability.FileManagement.File.FileIO 2624 2625**Parameters** 2626 2627| Name| Type | Mandatory| Description | 2628| ------ | ------ | ---- | ------------------------------------------------------------ | 2629| path | string | Yes | Application sandbox path of the file. | 2630| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| 2631 2632**Return value** 2633 2634 | Type | Description | 2635 | ------------------ | --------- | 2636 | [Stream](#stream) | Stream opened.| 2637 2638**Example** 2639 2640 ```ts 2641 let filePath = pathDir + "/test.txt"; 2642 let ss = fileio.createStreamSync(filePath, "r+"); 2643 ``` 2644 2645 2646## fileio.fdopenStream<sup>7+</sup> 2647 2648fdopenStream(fd: number, mode: string): Promise<Stream> 2649 2650Opens a stream based on an FD. This API uses a promise to return the result. 2651 2652> **NOTE** 2653> 2654> This API is deprecated since API version 9. Use [fs.fdopenStream](js-apis-file-fs.md#fsfdopenstream) instead. 2655 2656**System capability**: SystemCapability.FileManagement.File.FileIO 2657 2658**Parameters** 2659 2660 | Name | Type | Mandatory | Description | 2661 | ---- | ------ | ---- | ---------------------------------------- | 2662 | fd | number | Yes | FD of the target file. | 2663 | mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| 2664 2665**Return value** 2666 2667 | Type | Description | 2668 | --------------------------------- | --------- | 2669 | Promise<[Stream](#stream)> | Promise used to return the stream opened.| 2670 2671**Example** 2672 2673 ```ts 2674 import { BusinessError } from '@ohos.base'; 2675 let filePath = pathDir + "/test.txt"; 2676 let fd = fileio.openSync(filePath); 2677 fileio.fdopenStream(fd, "r+").then((stream: fileio.Stream) => { 2678 console.info("Stream opened"); 2679 }).catch((err: BusinessError) => { 2680 console.error("openStream failed with error:" + err); 2681 }); 2682 ``` 2683 2684 2685## fileio.fdopenStream<sup>7+</sup> 2686 2687fdopenStream(fd: number, mode: string, callback: AsyncCallback<Stream>): void 2688 2689Opens a stream based on an FD. This API uses an asynchronous callback to return the result. 2690 2691> **NOTE** 2692> 2693> This API is deprecated since API version 9. Use [fs.fdopenStream](js-apis-file-fs.md#fsfdopenstream-1) instead. 2694 2695**System capability**: SystemCapability.FileManagement.File.FileIO 2696 2697**Parameters** 2698 2699 | Name | Type | Mandatory | Description | 2700 | -------- | ---------------------------------------- | ---- | ---------------------------------------- | 2701 | fd | number | Yes | FD of the target file. | 2702 | mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| 2703 | callback | AsyncCallback<[Stream](#stream)> | Yes | Callback used to return the result. | 2704 2705**Example** 2706 2707 ```ts 2708 import { BusinessError } from '@ohos.base'; 2709 let filePath = pathDir + "/test.txt"; 2710 let fd = fileio.openSync(filePath); 2711 fileio.fdopenStream(fd, "r+", (err: BusinessError, stream: fileio.Stream) => { 2712 // Do something. 2713 }); 2714 ``` 2715 2716 2717## fileio.fdopenStreamSync<sup>7+</sup> 2718 2719fdopenStreamSync(fd: number, mode: string): Stream 2720 2721Opens a stream based on an FD. This API returns the result synchronously. 2722 2723> **NOTE** 2724> 2725> This API is deprecated since API version 9. Use [fs.fdopenStreamSync](js-apis-file-fs.md#fsfdopenstreamsync) instead. 2726 2727**System capability**: SystemCapability.FileManagement.File.FileIO 2728 2729**Parameters** 2730 2731 | Name | Type | Mandatory | Description | 2732 | ---- | ------ | ---- | ---------------------------------------- | 2733 | fd | number | Yes | FD of the target file. | 2734 | mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| 2735 2736**Return value** 2737 2738 | Type | Description | 2739 | ------------------ | --------- | 2740 | [Stream](#stream) | Stream opened.| 2741 2742**Example** 2743 2744 ```ts 2745 let filePath = pathDir + "/test.txt"; 2746 let fd = fileio.openSync(filePath); 2747 let ss = fileio.fdopenStreamSync(fd, "r+"); 2748 ``` 2749 2750 2751## fileio.fchown<sup>7+</sup> 2752 2753fchown(fd: number, uid: number, gid: number): Promise<void> 2754 2755Changes the file owner based on an FD. This API uses a promise to return the result. 2756 2757> **NOTE** 2758> 2759> This API is deprecated since API version 9. 2760 2761**System capability**: SystemCapability.FileManagement.File.FileIO 2762 2763**Parameters** 2764 2765 | Name | Type | Mandatory | Description | 2766 | ---- | ------ | ---- | ------------ | 2767 | fd | number | Yes | FD of the target file.| 2768 | uid | number | Yes | New UID. | 2769 | gid | number | Yes | New GID. | 2770 2771**Return value** 2772 2773 | Type | Description | 2774 | ------------------- | ---------------------------- | 2775 | Promise<void> | Promise that returns no value.| 2776 2777**Example** 2778 2779 ```ts 2780 import { BusinessError } from '@ohos.base'; 2781 let filePath = pathDir + "/test.txt"; 2782 let fd = fileio.openSync(filePath); 2783 let stat = fileio.statSync(filePath); 2784 fileio.fchown(fd, stat.uid, stat.gid).then(() => { 2785 console.info("File owner changed"); 2786 }).catch((err: BusinessError) => { 2787 console.error("chown failed with error:" + err); 2788 }); 2789 ``` 2790 2791 2792## fileio.fchown<sup>7+</sup> 2793 2794fchown(fd: number, uid: number, gid: number, callback: AsyncCallback<void>): void 2795 2796Changes the file owner based on an FD. This API uses an asynchronous callback to return the result. 2797 2798> **NOTE** 2799> 2800> This API is deprecated since API version 9. 2801 2802**System capability**: SystemCapability.FileManagement.File.FileIO 2803 2804**Parameters** 2805 2806 | Name | Type | Mandatory | Description | 2807 | -------- | ------------------------- | ---- | --------------- | 2808 | fd | number | Yes | FD of the target file. | 2809 | uid | number | Yes | New UID. | 2810 | gid | number | Yes | New GID. | 2811 | callback | AsyncCallback<void> | Yes | Callback used to return the result.| 2812 2813**Example** 2814 2815 ```ts 2816 import { BusinessError } from '@ohos.base'; 2817 let filePath = pathDir + "/test.txt"; 2818 let fd = fileio.openSync(filePath); 2819 let stat = fileio.statSync(filePath); 2820 fileio.fchown(fd, stat.uid, stat.gid, (err: BusinessError) => { 2821 // Do something. 2822 }); 2823 ``` 2824 2825 2826## fileio.fchownSync<sup>7+</sup> 2827 2828fchownSync(fd: number, uid: number, gid: number): void 2829 2830Changes the file owner based on an FD. This API returns the result synchronously. 2831 2832> **NOTE** 2833> 2834> This API is deprecated since API version 9. 2835 2836**System capability**: SystemCapability.FileManagement.File.FileIO 2837 2838**Parameters** 2839 2840 | Name | Type | Mandatory | Description | 2841 | ---- | ------ | ---- | ------------ | 2842 | fd | number | Yes | FD of the target file.| 2843 | uid | number | Yes | New UID. | 2844 | gid | number | Yes | New GID. | 2845 2846**Example** 2847 2848 ```ts 2849 let filePath = pathDir + "/test.txt"; 2850 let fd = fileio.openSync(filePath); 2851 let stat = fileio.statSync(filePath); 2852 fileio.fchownSync(fd, stat.uid, stat.gid); 2853 ``` 2854 2855 2856## fileio.lchown<sup>7+</sup> 2857 2858lchown(path: string, uid: number, gid: number): Promise<void> 2859 2860Changes the file owner (owner of the symbolic link, not the file referred to by the symbolic link) based on a file path. This API uses a promise to return the result. 2861 2862> **NOTE** 2863> 2864> This API is deprecated since API version 9. 2865 2866**System capability**: SystemCapability.FileManagement.File.FileIO 2867 2868**Parameters** 2869 2870| Name| Type | Mandatory| Description | 2871| ------ | ------ | ---- | -------------------------- | 2872| path | string | Yes | Application sandbox path of the file.| 2873| uid | number | Yes | New UID. | 2874| gid | number | Yes | New GID. | 2875 2876**Return value** 2877 2878 | Type | Description | 2879 | ------------------- | ---------------------------- | 2880 | Promise<void> | Promise that returns no value.| 2881 2882**Example** 2883 2884 ```ts 2885 import { BusinessError } from '@ohos.base'; 2886 let filePath = pathDir + "/test.txt"; 2887 let stat = fileio.statSync(filePath); 2888 fileio.lchown(filePath, stat.uid, stat.gid).then(() => { 2889 console.info("File owner changed"); 2890 }).catch((err: BusinessError) => { 2891 console.error("chown failed with error:" + err); 2892 }); 2893 ``` 2894 2895 2896## fileio.lchown<sup>7+</sup> 2897 2898lchown(path: string, uid: number, gid: number, callback: AsyncCallback<void>): void 2899 2900Changes the file owner (owner of the symbolic link, not the file referred to by the symbolic link) based on a file path. This API uses an asynchronous callback to return the result. 2901 2902> **NOTE** 2903> 2904> This API is deprecated since API version 9. 2905 2906**System capability**: SystemCapability.FileManagement.File.FileIO 2907 2908**Parameters** 2909 2910| Name | Type | Mandatory| Description | 2911| -------- | ------------------------- | ---- | ------------------------------ | 2912| path | string | Yes | Application sandbox path of the file. | 2913| uid | number | Yes | New UID. | 2914| gid | number | Yes | New GID. | 2915| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 2916 2917**Example** 2918 2919 ```ts 2920 import { BusinessError } from '@ohos.base'; 2921 let filePath = pathDir + "/test.txt"; 2922 let stat = fileio.statSync(filePath); 2923 fileio.lchown(filePath, stat.uid, stat.gid, (err: BusinessError) => { 2924 // Do something. 2925 }); 2926 ``` 2927 2928 2929## fileio.lchownSync<sup>7+</sup> 2930 2931lchownSync(path: string, uid: number, gid: number): void 2932 2933Changes the file owner based on a file path and changes the owner of the symbolic link (not the referenced file). This API returns the result synchronously. 2934 2935> **NOTE** 2936> 2937> This API is deprecated since API version 9. 2938 2939**System capability**: SystemCapability.FileManagement.File.FileIO 2940 2941**Parameters** 2942 2943| Name| Type | Mandatory| Description | 2944| ------ | ------ | ---- | -------------------------- | 2945| path | string | Yes | Application sandbox path of the file.| 2946| uid | number | Yes | New UID. | 2947| gid | number | Yes | New GID. | 2948 2949**Example** 2950 2951 ```ts 2952 let filePath = pathDir + "/test.txt"; 2953 let stat = fileio.statSync(filePath); 2954 fileio.lchownSync(filePath, stat.uid, stat.gid); 2955 ``` 2956 2957 2958## fileio.createWatcher<sup>7+</sup> 2959 2960createWatcher(filename: string, events: number, callback: AsyncCallback<number>): Watcher 2961 2962Listens for file or directory changes. This API uses an asynchronous callback to return the result. 2963 2964**System capability**: SystemCapability.FileManagement.File.FileIO 2965 2966**Parameters** 2967 2968| Name | Type | Mandatory| Description | 2969| -------- | --------------------------------- | ---- | ------------------------------------------------------------ | 2970| filePath | string | Yes | Application sandbox path of the file. | 2971| events | number | Yes | - **1**: The file or directory is renamed.<br>- **2**: The file or directory is modified.<br>- **3**: The file or directory is modified and renamed.| 2972| callback | AsyncCallback<number> | Yes | Called each time a change is detected. | 2973 2974**Return value** 2975 2976 | Type | Description | 2977 | -------------------- | ---------- | 2978 | [Watcher](#watcher7) | Promise used to return the result.| 2979 2980**Example** 2981 2982 ```ts 2983 let filePath = pathDir + "/test.txt"; 2984 fileio.createWatcher(filePath, 1, (err: BusinessError, event: number) => { 2985 console.info("event: " + event + "errmsg: " + JSON.stringify(err)); 2986 }); 2987 ``` 2988 2989 2990## Readout 2991 2992Obtains the file read result. This class applies only to the **read()** method. 2993 2994> **NOTE** 2995> 2996> This API is deprecated since API version 9. 2997 2998**System capability**: SystemCapability.FileManagement.File.FileIO 2999 3000| Name | Type | Read-Only | Writable | Description | 3001| --------- | ---------- | ---- | ---- | ----------------- | 3002| bytesRead | number | Yes | Yes | Length of the data read. | 3003| offset | number | Yes | Yes | Position of the buffer to which the data will be read in reference to the start address of the buffer.| 3004| buffer | ArrayBuffer | Yes | Yes | Buffer for storing the data read. | 3005 3006 3007## Stat 3008 3009Provides detailed file information. Before calling a method of the **Stat** class, use the [stat()](#fileiostat) method synchronously or asynchronously to create a **Stat** instance. 3010 3011> **NOTE** 3012> 3013> This API is deprecated since API version 9. Use [fs.stat](js-apis-file-fs.md#stat) instead. 3014 3015**System capability**: SystemCapability.FileManagement.File.FileIO 3016 3017### Properties 3018 3019| Name | Type | Read-Only | Writable | Description | 3020| ------ | ------ | ---- | ---- | ---------------------------------------- | 3021| dev | number | Yes | No | Major device number. | 3022| ino | number | Yes | No | File identifier, which varies with files on the same device. | 3023| mode | number | Yes | No | File type and permissions. The first four bits indicate the file type, and the last 12 bits indicate the permissions. The bit fields are described as follows:<br>- **0o170000**: mask used to obtain the file type.<br>- **0o140000**: The file is a socket.<br>- **0o120000**: The file is a symbolic link.<br>- **0o100000**: The file is a regular file.<br>- **0o060000**: The file is a block device.<br>- **0o040000**: The file is a directory.<br>- **0o020000**: The file is a character device.<br>- **0o010000**: The file is a named pipe (FIFO).<br>- **0o0700**: mask used to obtain the owner permissions.<br>- **0o0400**: The owner has the permission to read a regular file or a directory entry.<br>- **0o0200**: The owner has the permission to write a regular file or create and delete a directory entry.<br>- **0o0100**: The owner has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o0070**: mask used to obtain the user group permissions.<br>- **0o0040**: The user group has the permission to read a regular file or a directory entry.<br>- **0o0020**: The user group has the permission to write a regular file or create and delete a directory entry.<br>- **0o0010**: The user group has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o0007**: mask used to obtain the permissions of other users.<br>- **0o0004**: Other users have the permission to read a regular file or a directory entry.<br>- **0o0002**: Other users have the permission to write a regular file or create and delete a directory entry.<br>- **0o0001**: Other users have the permission to execute a regular file or search for the specified path in a directory.| 3024| nlink | number | Yes | No | Number of hard links in the file. | 3025| uid | number | Yes | No | ID of the file owner. | 3026| gid | number | Yes | No | ID of the user group of the file. | 3027| rdev | number | Yes | No | Minor device number. | 3028| size | number | Yes | No | File size, in bytes. This parameter is valid only for regular files. | 3029| blocks | number | Yes | No | Number of blocks occupied by a file. Each block is 512 bytes. | 3030| atime | number | Yes | No | Time when the file was last accessed. The value is the number of seconds elapsed since 00:00:00 on January 1, 1970. | 3031| mtime | number | Yes | No | Time when the file content was last modified. The value is the number of seconds elapsed since 00:00:00 on January 1, 1970. | 3032| ctime | number | Yes | No | Time when the file metadata was last modified. The value is the number of seconds elapsed since 00:00:00 on January 1, 1970. | 3033 3034 3035### isBlockDevice 3036 3037isBlockDevice(): boolean 3038 3039Checks whether this file is a block special file. A block special file supports access by block only, and it is cached when accessed. 3040 3041> **NOTE** 3042> 3043> This API is deprecated since API version 9. Use [fs.Stat.isBlockDevice](js-apis-file-fs.md#isblockdevice) instead. 3044 3045**System capability**: SystemCapability.FileManagement.File.FileIO 3046 3047**Return value** 3048 3049 | Type | Description | 3050 | ------- | ---------------- | 3051 | boolean | Returns **true** if it is a block special file; returns **false** otherwise.| 3052 3053**Example** 3054 3055 ```ts 3056 let filePath = pathDir + "/test.txt"; 3057 let isBLockDevice = fileio.statSync(filePath).isBlockDevice(); 3058 ``` 3059 3060 3061### isCharacterDevice 3062 3063isCharacterDevice(): boolean 3064 3065Checks whether this file is a character special file. A character special file supports random access, and it is not cached when accessed. 3066 3067> **NOTE** 3068> 3069> This API is deprecated since API version 9. Use [fs.Stat.isCharacterDevice](js-apis-file-fs.md#ischaracterdevice) instead. 3070 3071**System capability**: SystemCapability.FileManagement.File.FileIO 3072 3073**Return value** 3074 3075 | Type | Description | 3076 | ------- | ----------------- | 3077 | boolean | Returns **true** if it is a character special file; returns **false** otherwise. | 3078 3079**Example** 3080 3081 ```ts 3082 let filePath = pathDir + "/test.txt"; 3083 let isCharacterDevice = fileio.statSync(filePath).isCharacterDevice(); 3084 ``` 3085 3086 3087### isDirectory 3088 3089isDirectory(): boolean 3090 3091Checks whether this file is a directory. 3092 3093> **NOTE** 3094> 3095> This API is deprecated since API version 9. Use [fs.Stat.isDirectory](js-apis-file-fs.md#isdirectory) instead. 3096 3097**System capability**: SystemCapability.FileManagement.File.FileIO 3098 3099**Return value** 3100 3101 | Type | Description | 3102 | ------- | ------------- | 3103 | boolean | Returns **true** if it is a directory; returns **false** otherwise. | 3104 3105**Example** 3106 3107 ```ts 3108 let dirPath = pathDir + "/test"; 3109 let isDirectory = fileio.statSync(dirPath).isDirectory(); 3110 ``` 3111 3112 3113### isFIFO 3114 3115isFIFO(): boolean 3116 3117Checks whether this file is a named pipe (or FIFO). Named pipes are used for inter-process communication. 3118 3119> **NOTE** 3120> 3121> This API is deprecated since API version 9. Use [fs.Stat.isFIFO](js-apis-file-fs.md#isfifo) instead. 3122 3123**System capability**: SystemCapability.FileManagement.File.FileIO 3124 3125**Return value** 3126 3127 | Type | Description | 3128 | ------- | --------------------- | 3129 | boolean | Returns **true** if it is a named pipe; returns **false** otherwise.| 3130 3131**Example** 3132 3133 ```ts 3134 let filePath = pathDir + "/test.txt"; 3135 let isFIFO = fileio.statSync(filePath).isFIFO(); 3136 ``` 3137 3138 3139### isFile 3140 3141isFile(): boolean 3142 3143Checks whether this file is a regular file. 3144 3145> **NOTE** 3146> 3147> This API is deprecated since API version 9. Use [fs.Stat.isFile](js-apis-file-fs.md#isfile) instead. 3148 3149**System capability**: SystemCapability.FileManagement.File.FileIO 3150 3151**Return value** 3152 3153 | Type | Description | 3154 | ------- | --------------- | 3155 | boolean | Returns **true** if it is a regular file; returns **false** otherwise.| 3156 3157**Example** 3158 3159 ```ts 3160 let filePath = pathDir + "/test.txt"; 3161 let isFile = fileio.statSync(filePath).isFile(); 3162 ``` 3163 3164 3165### isSocket 3166 3167isSocket(): boolean 3168 3169Checks whether this file is a socket. 3170 3171> **NOTE** 3172> 3173> This API is deprecated since API version 9. Use [fs.Stat.isSocket](js-apis-file-fs.md#issocket) instead. 3174 3175**System capability**: SystemCapability.FileManagement.File.FileIO 3176 3177**Return value** 3178 3179 | Type | Description | 3180 | ------- | -------------- | 3181 | boolean | Returns **true** if it is a socket; returns **false** otherwise.| 3182 3183**Example** 3184 3185 ```ts 3186 let filePath = pathDir + "/test.txt"; 3187 let isSocket = fileio.statSync(filePath).isSocket(); 3188 ``` 3189 3190 3191### isSymbolicLink 3192 3193isSymbolicLink(): boolean 3194 3195Checks whether this file is a symbolic link. 3196 3197> **NOTE** 3198> 3199> This API is deprecated since API version 9. Use [fs.Stat.isSymbolicLink](js-apis-file-fs.md#issymboliclink) instead. 3200 3201**System capability**: SystemCapability.FileManagement.File.FileIO 3202 3203**Return value** 3204 3205 | Type | Description | 3206 | ------- | --------------- | 3207 | boolean | Returns **true** if it is a symbolic link; returns **false** otherwise. | 3208 3209**Example** 3210 3211 ```ts 3212 let filePath = pathDir + "/test"; 3213 let isSymbolicLink = fileio.statSync(filePath).isSymbolicLink(); 3214 ``` 3215 3216 3217## Watcher<sup>7+</sup> 3218 3219Listens for the changes of a file. You can call the **Watcher.stop()** method synchronously or asynchronously to stop the listening. 3220 3221 3222### stop<sup>7+</sup> 3223 3224stop(): Promise<void> 3225 3226Stops the **watcher** instance. This API uses a promise to return the result. 3227 3228**System capability**: SystemCapability.FileManagement.File.FileIO 3229 3230**Example** 3231 3232 ```ts 3233 let filePath = pathDir + "/test.txt"; 3234 let watcher = fileio.createWatcher(filePath, 1, (err: BusinessError, event: number) => { 3235 console.info("event: " + event + "errmsg: " + JSON.stringify(err)); 3236 }); 3237 watcher.stop().then(() => { 3238 console.info("Watcher stopped"); 3239 }); 3240 ``` 3241 3242 3243### stop<sup>7+</sup> 3244 3245stop(callback: AsyncCallback<void>): void 3246 3247Stops the **watcher** instance. This API uses an asynchronous callback to return the result. 3248 3249**System capability**: SystemCapability.FileManagement.File.FileIO 3250 3251**Parameters** 3252 3253 | Name | Type | Mandatory | Description | 3254 | -------- | ------------------------- | ---- | ---------------------- | 3255 | callback | AsyncCallback<void> | Yes | Callback used to return the result.| 3256 3257**Example** 3258 3259 ```ts 3260 let filePath = pathDir + "/test.txt"; 3261 let watcher = fileio.createWatcher(filePath, 1, (err: BusinessError, event: number) => { 3262 console.info("event: " + event + "errmsg: " + JSON.stringify(err)); 3263 }); 3264 watcher.stop(() => { 3265 console.info("Watcher stopped"); 3266 }) 3267 ``` 3268 3269 3270## Stream 3271 3272Provides a stream for file operations. Before calling any API of the **Stream** class, use **createStream()** to create a **Stream** instance synchronously or asynchronously. 3273 3274> **NOTE** 3275> 3276> This API is deprecated since API version 9. Use [fs.Stream](js-apis-file-fs.md#stream) instead. 3277 3278### close<sup>7+</sup> 3279 3280close(): Promise<void> 3281 3282Closes the stream. This API uses a promise to return the result. 3283 3284> **NOTE** 3285> 3286> This API is deprecated since API version 9. Use [fs.Stream.close](js-apis-file-fs.md#close) instead. 3287 3288**System capability**: SystemCapability.FileManagement.File.FileIO 3289 3290**Return value** 3291 3292 | Type | Description | 3293 | ------------------- | ------------- | 3294 | Promise<void> | Promise used to return the result.| 3295 3296**Example** 3297 3298 ```ts 3299 import { BusinessError } from '@ohos.base'; 3300 let filePath = pathDir + "/test.txt"; 3301 let ss = fileio.createStreamSync(filePath, "r+"); 3302 ss.close().then(() => { 3303 console.info("File stream closed"); 3304 }).catch((err: BusinessError) => { 3305 console.error("close fileStream failed with error:" + err); 3306 }); 3307 ``` 3308 3309 3310### close<sup>7+</sup> 3311 3312close(callback: AsyncCallback<void>): void 3313 3314Closes this stream. This API uses an asynchronous callback to return the result. 3315 3316> **NOTE** 3317> 3318> This API is deprecated since API version 9. Use [fs.Stream.close](js-apis-file-fs.md#close-1) instead. 3319 3320**System capability**: SystemCapability.FileManagement.File.FileIO 3321 3322**Parameters** 3323 3324 | Name | Type | Mandatory | Description | 3325 | -------- | ------------------------- | ---- | ------------- | 3326 | callback | AsyncCallback<void> | Yes | Callback used to return the result.| 3327 3328**Example** 3329 3330 ```ts 3331 import { BusinessError } from '@ohos.base'; 3332 let filePath = pathDir + "/test.txt"; 3333 let ss = fileio.createStreamSync(filePath, "r+"); 3334 ss.close((err: BusinessError) => { 3335 // Do something. 3336 }); 3337 ``` 3338 3339 3340### closeSync 3341 3342closeSync(): void 3343 3344Closes this stream. This API returns the result synchronously. 3345 3346> **NOTE** 3347> 3348> This API is deprecated since API version 9. Use [fs.Stream.closeSync](js-apis-file-fs.md#closesync) instead. 3349 3350**System capability**: SystemCapability.FileManagement.File.FileIO 3351 3352**Example** 3353 3354 ```ts 3355 let filePath = pathDir + "/test.txt"; 3356 let ss = fileio.createStreamSync(filePath, "r+"); 3357 ss.closeSync(); 3358 ``` 3359 3360 3361### flush<sup>7+</sup> 3362 3363flush(): Promise<void> 3364 3365Flushes this stream. This API uses a promise to return the result. 3366 3367> **NOTE** 3368> 3369> This API is deprecated since API version 9. Use [fs.Stream.flush](js-apis-file-fs.md#flush) instead. 3370 3371**System capability**: SystemCapability.FileManagement.File.FileIO 3372 3373**Return value** 3374 3375 | Type | Description | 3376 | ------------------- | ------------- | 3377 | Promise<void> | Promise used to return the result.| 3378 3379**Example** 3380 3381 ```ts 3382 import { BusinessError } from '@ohos.base'; 3383 let filePath = pathDir + "/test.txt"; 3384 let ss = fileio.createStreamSync(filePath, "r+"); 3385 ss.flush().then(() => { 3386 console.info("Stream flushed"); 3387 }).catch((err: BusinessError) => { 3388 console.error("flush failed with error:" + err); 3389 }); 3390 ``` 3391 3392 3393### flush<sup>7+</sup> 3394 3395flush(callback: AsyncCallback<void>): void 3396 3397Flushes this stream. This API uses an asynchronous callback to return the result. 3398 3399> **NOTE** 3400> 3401> This API is deprecated since API version 9. Use [fs.Stream.flush](js-apis-file-fs.md#flush-1) instead. 3402 3403**System capability**: SystemCapability.FileManagement.File.FileIO 3404 3405**Parameters** 3406 3407 | Name | Type | Mandatory | Description | 3408 | -------- | ------------------------- | ---- | -------------- | 3409 | callback | AsyncCallback<void> | Yes | Callback used to return the result.| 3410 3411**Example** 3412 3413 ```ts 3414 import { BusinessError } from '@ohos.base'; 3415 let filePath = pathDir + "/test.txt"; 3416 let ss = fileio.createStreamSync(filePath, "r+"); 3417 ss.flush((err: BusinessError) => { 3418 // Do something. 3419 }); 3420 ``` 3421 3422 3423### flushSync<sup>7+</sup> 3424 3425flushSync(): void 3426 3427Flushes this stream. This API returns the result synchronously. 3428 3429> **NOTE** 3430> 3431> This API is deprecated since API version 9. Use [fs.Stream.flushSync](js-apis-file-fs.md#flushsync) instead. 3432 3433**System capability**: SystemCapability.FileManagement.File.FileIO 3434 3435**Example** 3436 3437 ```ts 3438 let filePath = pathDir + "/test.txt"; 3439 let ss = fileio.createStreamSync(filePath, "r+"); 3440 ss.flushSync(); 3441 ``` 3442 3443 3444### write<sup>7+</sup> 3445 3446write(buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; position?: number; encoding?: string; }): Promise<number> 3447 3448Writes data into the stream. This API uses a promise to return the result. 3449 3450> **NOTE** 3451> 3452> This API is deprecated since API version 9. Use [fs.Stream.write](js-apis-file-fs.md#write) instead. 3453 3454**System capability**: SystemCapability.FileManagement.File.FileIO 3455 3456**Parameters** 3457 3458 | Name | Type | Mandatory | Description | 3459 | ------- | ------------------------------- | ---- | ---------------------------------------- | 3460 | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | 3461 | options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to write in reference to the start address of the data. This parameter is optional. The default value is **0**.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.<br>Constraints: offset + length <= Buffer size | 3462 3463**Return value** 3464 3465 | Type | Description | 3466 | --------------------- | -------- | 3467 | Promise<number> | Promise used to return the length of the data written.| 3468 3469**Example** 3470 3471 ```ts 3472 import { BusinessError } from '@ohos.base'; 3473 let filePath = pathDir + "/test.txt"; 3474 let ss = fileio.createStreamSync(filePath, "r+"); 3475 class Option { 3476 offset: number = 0; 3477 length: number = 4096; 3478 position: number = 0; 3479 encoding: string = 'utf-8'; 3480 } 3481 let option = new Option(); 3482 option.offset = 1; 3483 option.length = 5; 3484 option.position = 5; 3485 ss.write("hello, world", option).then((number: number) => { 3486 console.info("write succeed and size is:" + number); 3487 }).catch((err: BusinessError) => { 3488 console.error("write failed with error:" + err); 3489 }); 3490 ``` 3491 3492 3493### write<sup>7+</sup> 3494 3495write(buffer: ArrayBuffer|string, options: { offset?: number; length?: number; position?: number; encoding?: string; }, callback: AsyncCallback<number>): void 3496 3497Writes data to this stream. This API uses an asynchronous callback to return the result. 3498 3499> **NOTE** 3500> 3501> This API is deprecated since API version 9. Use [fs.Stream.write](js-apis-file-fs.md#write-1) instead. 3502 3503**System capability**: SystemCapability.FileManagement.File.FileIO 3504 3505**Parameters** 3506 3507 | Name | Type | Mandatory| Description | 3508 | -------- | ------------------------------- | ---- | ------------------------------------------------------------ | 3509 | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | 3510 | options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to write in reference to the start address of the data. This parameter is optional. The default value is **0**.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.<br>Constraints: offset + length <= Buffer size| 3511 | callback | AsyncCallback<number> | Yes | Callback used to return the result. | 3512 3513**Example** 3514 3515 ```ts 3516 import { BusinessError } from '@ohos.base'; 3517 let filePath = pathDir + "/test.txt"; 3518 let ss = fileio.createStreamSync(filePath, "r+"); 3519 class Option { 3520 offset: number = 0; 3521 length: number = 4096; 3522 position: number = 0; 3523 encoding: string = 'utf-8'; 3524 } 3525 let option = new Option(); 3526 option.offset = 1; 3527 option.length = 5; 3528 option.position = 5; 3529 ss.write("hello, world", option, (err: BusinessError, bytesWritten: number) => { 3530 if (bytesWritten) { 3531 // Do something. 3532 console.info("write succeed and size is:" + bytesWritten); 3533 } 3534 }); 3535 ``` 3536 3537 3538### writeSync<sup>7+</sup> 3539 3540writeSync(buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; position?: number; encoding?: string; }): number 3541 3542Writes data to this stream. This API returns the result synchronously. 3543 3544> **NOTE** 3545> 3546> This API is deprecated since API version 9. Use [fs.Stream.writeSync](js-apis-file-fs.md#writesync) instead. 3547 3548**System capability**: SystemCapability.FileManagement.File.FileIO 3549 3550**Parameters** 3551 3552 | Name | Type | Mandatory | Description | 3553 | ------- | ------------------------------- | ---- | ---------------------------------------- | 3554 | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | 3555 | options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to write in reference to the start address of the data. This parameter is optional. The default value is **0**.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.<br>Constraints: offset + length <= Buffer size | 3556 3557**Return value** 3558 3559 | Type | Description | 3560 | ------ | -------- | 3561 | number | Length of the data written in the file.| 3562 3563**Example** 3564 3565 ```ts 3566 let filePath = pathDir + "/test.txt"; 3567 let ss = fileio.createStreamSync(filePath,"r+"); 3568 class Option { 3569 offset: number = 0; 3570 length: number = 4096; 3571 position: number = 0; 3572 encoding: string = 'utf-8'; 3573 } 3574 let option = new Option(); 3575 option.offset = 1; 3576 option.length = 5; 3577 option.position = 5; 3578 let num = ss.writeSync("hello, world", option); 3579 ``` 3580 3581 3582### read<sup>7+</sup> 3583 3584read(buffer: ArrayBuffer, options?: { position?: number; offset?: number; length?: number; }): Promise<ReadOut> 3585 3586Reads data from the stream. This API uses a promise to return the result. 3587 3588> **NOTE** 3589> 3590> This API is deprecated since API version 9. Use [fs.Stream.read](js-apis-file-fs.md#read) instead. 3591 3592**System capability**: SystemCapability.FileManagement.File.FileIO 3593 3594**Parameters** 3595 3596 | Name | Type | Mandatory | Description | 3597 | ------- | ----------- | ---- | ---------------------------------------- | 3598 | buffer | ArrayBuffer | Yes | Buffer used to store the file read. | 3599 | options | Object | No | The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. This parameter is optional. The default value is **0**.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size | 3600 3601**Return value** 3602 3603 | Type | Description | 3604 | ---------------------------------- | ------ | 3605 | Promise<[ReadOut](#readout)> | Promise used to return the data read.| 3606 3607**Example** 3608 3609 ```ts 3610 import { BusinessError } from '@ohos.base'; 3611 import buffer from '@ohos.buffer'; 3612 let filePath = pathDir + "/test.txt"; 3613 let ss = fileio.createStreamSync(filePath, "r+"); 3614 let arrayBuffer = new ArrayBuffer(4096); 3615 class Option { 3616 offset: number = 0; 3617 length: number = 4096; 3618 position: number = 0; 3619 } 3620 let option = new Option(); 3621 option.offset = 1; 3622 option.length = 5; 3623 option.position = 5; 3624 ss.read(arrayBuffer, option).then((readResult: fileio.ReadOut) => { 3625 console.info("Read data successfully"); 3626 let buf = buffer.from(arrayBuffer, 0, readResult.bytesRead); 3627 console.info(`The content of file: ${buf.toString()}`); 3628 }).catch((err: BusinessError) => { 3629 console.error("read data failed with error:" + err); 3630 }); 3631 ``` 3632 3633 3634### read<sup>7+</sup> 3635 3636read(buffer: ArrayBuffer, options: { position?: number; offset?: number; length?: number; }, callback: AsyncCallback<ReadOut>): void 3637 3638Reads data from this stream. This API uses an asynchronous callback to return the result. 3639 3640> **NOTE** 3641> 3642> This API is deprecated since API version 9. Use [fs.Stream.read](js-apis-file-fs.md#read-1) instead. 3643 3644**System capability**: SystemCapability.FileManagement.File.FileIO 3645 3646**Parameters** 3647 3648 | Name | Type | Mandatory | Description | 3649 | -------- | ---------------------------------------- | ---- | ---------------------------------------- | 3650 | buffer | ArrayBuffer | Yes | Buffer used to store the file read. | 3651 | options | Object | No | The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. This parameter is optional. The default value is **0**.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size | 3652 | callback | AsyncCallback<[ReadOut](#readout)> | Yes | Callback used to return the result. | 3653 3654**Example** 3655 3656 ```ts 3657 import { BusinessError } from '@ohos.base'; 3658 import buffer from '@ohos.buffer'; 3659 let filePath = pathDir + "/test.txt"; 3660 let ss = fileio.createStreamSync(filePath, "r+"); 3661 let arrayBuffer = new ArrayBuffer(4096); 3662 class Option { 3663 offset: number = 0; 3664 length: number = 4096; 3665 position: number = 0; 3666 } 3667 let option = new Option(); 3668 option.offset = 1; 3669 option.length = 5; 3670 option.position = 5; 3671 ss.read(arrayBuffer, option, (err: BusinessError, readResult: fileio.ReadOut) => { 3672 if (readResult.bytesRead) { 3673 console.info("Read data successfully"); 3674 let buf = buffer.from(arrayBuffer, 0, readResult.bytesRead); 3675 console.info(`The content of file: ${buf.toString()}`); 3676 } 3677 }); 3678 ``` 3679 3680 3681### readSync<sup>7+</sup> 3682 3683readSync(buffer: ArrayBuffer, options?: { position?: number; offset?: number; length?: number; }): number 3684 3685Reads data from this stream. This API returns the result synchronously. 3686 3687> **NOTE** 3688> 3689> This API is deprecated since API version 9. Use [fs.Stream.readSync](js-apis-file-fs.md#readsync) instead. 3690 3691**System capability**: SystemCapability.FileManagement.File.FileIO 3692 3693**Parameters** 3694 3695 | Name | Type | Mandatory | Description | 3696 | ------- | ----------- | ---- | ---------------------------------------- | 3697 | buffer | ArrayBuffer | Yes | Buffer used to store the file read. | 3698 | options | Object | No | The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. This parameter is optional. The default value is **0**.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size | 3699 3700**Return value** 3701 3702 | Type | Description | 3703 | ------ | -------- | 3704 | number | Length of the data read.| 3705 3706**Example** 3707 3708 ```ts 3709 let filePath = pathDir + "/test.txt"; 3710 let ss = fileio.createStreamSync(filePath, "r+"); 3711 class Option { 3712 offset: number = 0; 3713 length: number = 4096; 3714 position: number = 0; 3715 } 3716 let option = new Option(); 3717 option.offset = 1; 3718 option.length = 5; 3719 option.position = 5; 3720 let buf = new ArrayBuffer(4096) 3721 let num = ss.readSync(buf, option); 3722 ``` 3723 3724 3725## Dir 3726 3727Manages directories. Before calling a method of the **Dir** class, use the **opendir()** method synchronously or asynchronously to create a **Dir** instance. 3728 3729> **NOTE** 3730> 3731> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile) instead. 3732 3733### read 3734 3735read(): Promise<Dirent> 3736 3737Reads the next directory entry. This API uses a promise to return the result. 3738 3739> **NOTE** 3740> 3741> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile) instead. 3742 3743**System capability**: SystemCapability.FileManagement.File.FileIO 3744 3745**Return value** 3746 3747 | Type | Description | 3748 | -------------------------------- | ------------- | 3749 | Promise<[Dirent](#dirent)> | Promise used to return the result.| 3750 3751**Example** 3752 3753 ```ts 3754 import { BusinessError } from '@ohos.base'; 3755 dir.read().then((dirent: fileio.Dirent) => { 3756 console.log("read succeed, the name of dirent is " + dirent.name); 3757 }).catch((err: BusinessError) => { 3758 console.error("read failed with error:" + err); 3759 }); 3760 ``` 3761 3762 3763### read 3764 3765read(callback: AsyncCallback<Dirent>): void 3766 3767Reads the next directory entry. This API uses an asynchronous callback to return the result. 3768 3769> **NOTE** 3770> 3771> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile-1) instead. 3772 3773**System capability**: SystemCapability.FileManagement.File.FileIO 3774 3775**Parameters** 3776 3777 | Name | Type | Mandatory | Description | 3778 | -------- | -------------------------------------- | ---- | ---------------- | 3779 | callback | AsyncCallback<[Dirent](#dirent)> | Yes | Callback used to return the result.| 3780 3781**Example** 3782 3783 ```ts 3784 import { BusinessError } from '@ohos.base'; 3785 dir.read((err: BusinessError, dirent: fileio.Dirent) => { 3786 if (dirent) { 3787 // Do something. 3788 console.log("read succeed, the name of file is " + dirent.name); 3789 } 3790 }); 3791 ``` 3792 3793 3794### readSync 3795 3796readSync(): Dirent 3797 3798Reads the next directory entry. This API returns the result synchronously. 3799 3800> **NOTE** 3801> 3802> This API is deprecated since API version 9. Use [fs.listFileSync](js-apis-file-fs.md#fslistfilesync) instead. 3803 3804**System capability**: SystemCapability.FileManagement.File.FileIO 3805 3806**Return value** 3807 3808 | Type | Description | 3809 | ----------------- | -------- | 3810 | [Dirent](#dirent) | Directory entry read.| 3811 3812**Example** 3813 3814 ```ts 3815 let dirent = dir.readSync(); 3816 ``` 3817 3818 3819### close<sup>7+</sup> 3820 3821close(): Promise<void> 3822 3823Closes a directory. This API uses a promise to return the result. After a directory is closed, the FD in **Dir** will be released and no directory entry can be read from **Dir**. 3824 3825> **NOTE** 3826> 3827> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile) instead. 3828 3829**System capability**: SystemCapability.FileManagement.File.FileIO 3830 3831**Example** 3832 3833 ```ts 3834 import { BusinessError } from '@ohos.base'; 3835 dir.close().then(() => { 3836 console.info("close dir successfully"); 3837 }); 3838 ``` 3839 3840 3841### close<sup>7+</sup> 3842 3843close(callback: AsyncCallback<void>): void 3844 3845Closes a directory. This API uses an asynchronous callback to return the result. After a directory is closed, the FD in **Dir** will be released and no directory entry can be read from **Dir**. 3846 3847> **NOTE** 3848> 3849> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile-1) instead. 3850 3851**System capability**: SystemCapability.FileManagement.File.FileIO 3852 3853**Example** 3854 3855 ```ts 3856 import { BusinessError } from '@ohos.base'; 3857 dir.close((err: BusinessError) => { 3858 console.info("close dir successfully"); 3859 }); 3860 ``` 3861 3862 3863### closeSync 3864 3865closeSync(): void 3866 3867Closes a directory. After a directory is closed, the FD in **Dir** will be released and no directory entry can be read from **Dir**. 3868 3869> **NOTE** 3870> 3871> This API is deprecated since API version 9. Use [fs.listFileSync](js-apis-file-fs.md#fslistfilesync) instead. 3872 3873**System capability**: SystemCapability.FileManagement.File.FileIO 3874 3875**Example** 3876 3877 ```ts 3878 dir.closeSync(); 3879 ``` 3880 3881 3882## Dirent 3883 3884Provides information about files and directories. Before calling an API of the **Dirent** class, use [dir.read()](#read) synchronously or asynchronously to create a **Dirent** instance. 3885 3886> **NOTE** 3887> 3888> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile) instead. 3889 3890**System capability**: SystemCapability.FileManagement.File.FileIO 3891 3892### Properties 3893 3894| Name | Type | Read-Only | Writable | Description | 3895| ---- | ------ | ---- | ---- | ------- | 3896| name | string | Yes | No | Directory entry name.| 3897 3898 3899### isBlockDevice 3900 3901isBlockDevice(): boolean 3902 3903Checks whether this directory entry is a block special file. A block special file supports access by block only, and it is cached when accessed. 3904 3905> **NOTE** 3906> 3907> This API is deprecated since API version 9. 3908 3909**System capability**: SystemCapability.FileManagement.File.FileIO 3910 3911**Return value** 3912 3913 | Type | Description | 3914 | ------- | ---------------- | 3915 | boolean | Returns **true** if it is a block special file; returns **false** otherwise.| 3916 3917**Example** 3918 3919 ```ts 3920 let dir = fileio.opendirSync(pathDir); 3921 let isBLockDevice = dir.readSync().isBlockDevice(); 3922 ``` 3923 3924 3925### isCharacterDevice 3926 3927isCharacterDevice(): boolean 3928 3929Checks whether this directory entry is a character special file. A character special file supports random access, and it is not cached when accessed. 3930 3931> **NOTE** 3932> 3933> This API is deprecated since API version 9. 3934 3935**System capability**: SystemCapability.FileManagement.File.FileIO 3936 3937**Return value** 3938 3939 | Type | Description | 3940 | ------- | ----------------- | 3941 | boolean | Returns **true** if it is a character special file; returns **false** otherwise.| 3942 3943**Example** 3944 3945 ```ts 3946 let dir = fileio.opendirSync(pathDir); 3947 let isCharacterDevice = dir.readSync().isCharacterDevice(); 3948 ``` 3949 3950 3951### isDirectory 3952 3953isDirectory(): boolean 3954 3955Checks whether this directory entry is a folder. 3956 3957> **NOTE** 3958> 3959> This API is deprecated since API version 9. 3960 3961**System capability**: SystemCapability.FileManagement.File.FileIO 3962 3963**Return value** 3964 3965 | Type | Description | 3966 | ------- | ------------- | 3967 | boolean | Returns **true** if it is a folder; returns **false** otherwise. | 3968 3969**Example** 3970 3971 ```ts 3972 let dir = fileio.opendirSync(pathDir); 3973 let isDirectory = dir.readSync().isDirectory(); 3974 ``` 3975 3976 3977### isFIFO 3978 3979isFIFO(): boolean 3980 3981Checks whether this directory entry is a named pipe (also called FIFO). Named pipes are used for inter-process communication. 3982 3983> **NOTE** 3984> 3985> This API is deprecated since API version 9. 3986 3987**System capability**: SystemCapability.FileManagement.File.FileIO 3988 3989**Return value** 3990 3991 | Type | Description | 3992 | ------- | --------------- | 3993 | boolean | Returns **true** if it is a named pipe; returns **false** otherwise.| 3994 3995**Example** 3996 3997 ```ts 3998 let dir = fileio.opendirSync(pathDir); 3999 let isFIFO = dir.readSync().isFIFO(); 4000 ``` 4001 4002 4003### isFile 4004 4005isFile(): boolean 4006 4007Checks whether this directory entry is a regular file. 4008 4009> **NOTE** 4010> 4011> This API is deprecated since API version 9. 4012 4013**System capability**: SystemCapability.FileManagement.File.FileIO 4014 4015**Return value** 4016 4017 | Type | Description | 4018 | ------- | --------------- | 4019 | boolean | Returns **true** if it is a regular file; returns **false** otherwise. | 4020 4021**Example** 4022 4023 ```ts 4024 let dir = fileio.opendirSync(pathDir); 4025 let isFile = dir.readSync().isFile(); 4026 ``` 4027 4028 4029### isSocket 4030 4031isSocket(): boolean 4032 4033Checks whether this directory entry is a socket. 4034 4035> **NOTE** 4036> 4037> This API is deprecated since API version 9. 4038 4039**System capability**: SystemCapability.FileManagement.File.FileIO 4040 4041**Return value** 4042 4043 | Type | Description | 4044 | ------- | -------------- | 4045 | boolean | Returns **true** if it is a socket; returns **false** otherwise. | 4046 4047**Example** 4048 4049 ```ts 4050 let dir = fileio.opendirSync(pathDir); 4051 let isSocket = dir.readSync().isSocket(); 4052 ``` 4053 4054 4055### isSymbolicLink 4056 4057isSymbolicLink(): boolean 4058 4059Checks whether this directory entry is a symbolic link. 4060 4061> **NOTE** 4062> 4063> This API is deprecated since API version 9. 4064 4065**System capability**: SystemCapability.FileManagement.File.FileIO 4066 4067**Return value** 4068 4069 | Type | Description | 4070 | ------- | --------------- | 4071 | boolean | Returns **true** if it is a symbolic link; returns **false** otherwise.| 4072 4073**Example** 4074 4075 ```ts 4076 let dir = fileio.opendirSync(pathDir); 4077 let isSymbolicLink = dir.readSync().isSymbolicLink(); 4078 ``` 4079