1# File Management Subsystem Changelog 2 3## cl.filemanagement.1 fileio API Changes 4 5Deprecated the **fileio** APIs, which do not return error codes; added APIs that return error codes. 6 7**Change Impact** 8 9For applications developed based on earlier versions, pay attention to the iterative update of deprecated APIs. The specifications of the new APIs are slightly adjusted. Pay attention to the usage of the new APIs. 10 11**Key API/Component Changes** 12 13The APIs of **@ohos.fileio** do not support error code handling and are deprecated. New APIs with minor changes in parameters are added in **@ohos.file.fs** to support unified error code handling. The functionalities of the APIs remain unchanged. 14 15| Module | Method/Attribute/Enum/Constant | Change Type| 16| ------------------------- | ------------------------------------------------------------ | -------- | 17| @ohos.fileio | **function** open(path: string, flags?: number, mode?: number, callback?: AsyncCallback<number>): void \| Promise<number>; | Deprecated | 18| @ohos.fileio | **function** openSync(path: string, flags?: number, mode?: number): number; | Deprecated | 19| @ohos.file.fs | **function** open(path: string, mode?: number, callback?: AsyncCallback<File>): void \| Promise<File>; | Added | 20| @ohos.file.fs | **function** openSync(path: string, mode?: number): File; | Added | 21| @ohos.fileio | **function** read(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: number; position?: number; }, callback?: AsyncCallback<ReadOut>): void \| Promise<ReadOut>; | Deprecated | 22| @ohos.fileio | **function** readSync(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: number; position?: number; }): number; | Deprecated | 23| @ohos.file.fs | **function** read(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: number; }, callback?: AsyncCallback<number>): void \| Promise<number>; | Added | 24| @ohos.file.fs | **function** readSync(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: number; }): number; | Added | 25| @ohos.fileio | **function** stat(path: string, callback?: AsyncCallback<Stat>): void \| Promise<Stat>; | Deprecated | 26| @ohos.fileio | **function** statSync(path: string): Stat; | Deprecated | 27| @ohos.fileio | **function** fstat(fd: number, callback?: AsyncCallback<Stat>): void \| Promise<Stat>; | Deprecated | 28| @ohos.fileio | **function** fstatSync(fd: number): Stat; | Deprecated | 29| @ohos.file.fs | **function** stat(file: string \| number, callback?: AsyncCallback<Stat>): void \| Promise<Stat>; | Added | 30| @ohos.file.fs | **function** statSync(file: string \| number): Stat; | Added | 31| @ohos.fileio | **function** truncate(path: string, len?: number, callback?: AsyncCallback<void>): void \| Promise<void>; | Deprecated | 32| @ohos.fileio | **function** truncateSync(path: string, len?: number): void; | Deprecated | 33| @ohos.fileio | **function** ftruncate(fd: number, len?: number, callback?: AsyncCallback<void>): void \| Promise<void>; | Deprecated | 34| @ohos.fileio | **function** ftruncateSync(fd: number, len?: number): void; | Deprecated | 35| @ohos.file.fs | **function** truncate(file: string \| number, len?: number, callback?: AsyncCallback<void>): void \| Promise<void>; | Added | 36| @ohos.file.fs | **function** truncateSync(file: string \| number, len?: number): void; | Added | 37| @ohos.fileio | **function** write(fd: number, buffer: ArrayBuffer \| string, options?: { offset?: number; length?: number; position?: number; encoding?: string; }, callback?: AsyncCallback<number>): void \| Promise<void>; | Deprecated | 38| @ohos.fileio | **function** writeSync(fd: number, buffer: ArrayBuffer \| string, options?: { offset?: number; length?: number; position?: number; encoding?: string; }): number; | Deprecated | 39| @ohos.file.fs | **function** write(fd: number, buffer: ArrayBuffer \| string, options?: { offset?: number; length?: number; encoding?: string; }, callback?: AsyncCallback<number>): void \| Promise<void>; | Added | 40| @ohos.file.fs | **function** writeSync(fd: number, buffer: ArrayBuffer \| string, options?: { offset?: number; length?: number; encoding?: string; }): number; | Added | 41 42**Adaptation Guide** 43 441. Change the module to import. 45 46 Change **import fileio from '@ohos.fileio'** to **import fs from '@ohos.file.fs'**. 47 482. Change the exception handling method. 49 50 Sample code for exception handling in a synchronous API: 51 52 ```js 53 import fs from '@ohos.file.fs' 54 55 try { 56 let file = fs.openSync(path, fs.OpenMode.READ_ONLY); 57 } catch (err) { 58 console.error("openSync errCode:" + err.code + ", errMessage:" + err.message); 59 } 60 ``` 61 62 Sample code for exception handling in an asynchronous API (promise): 63 64 ```js 65 import fs from '@ohos.file.fs' 66 67 try { 68 let file = await fs.open(path, fs.OpenMode.READ_ONLY); 69 } catch (err) { 70 console.error("open promise errCode:" + err.code + ", errMessage:" + err.message); 71 } 72 73 ``` 74 75 Sample code for exception handling in an asynchronous API (callback): 76 77 ```js 78 import fs from '@ohos.file.fs' 79 80 try { 81 fs.open(path, fs.OpenMode.READ_ONLY, function(e, file){ // Asynchronous thread errors (such as a syscall error) are obtained via a callback. 82 if (e) { 83 console.error("open in async errCode:" + e.code + ", errMessage:" + e.message); 84 } 85 }); 86 } catch (err) {// Main thread errors (such as invalid parameters) are obtained by try catch. 87 console.error("open callback errCode:" + err.code + ", errMessage:" + err.message); 88 } 89 ``` 90 91