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