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