1e41f4b71Sopenharmony_ci# File Management Subsystem ChangeLog
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## cl.filemanagement.1 File I/O API Changes
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ciThe return value of file I/O APIs of **file_api** does not contain the error code. The original APIs are deprecated, and new APIs are added.
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci**Change Impacts**
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ciFor applications developed based on earlier versions, pay attention to the iterative update of discarded APIs. The specifications of the new APIs are slightly adjusted. Pay attention to the usage of the new APIs.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci**Key API/Component Changes**
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ciFor the adaptation to the unified API exception handling mode, related file I/O APIs are deprecated, and corresponding new APIs are added. Original APIs are stored in **@ohos.fileio**, and the new ones are stored in **@ohos.file.fs**. The newly added APIs support unified error code handling specifications and function the same as the original APIs. The parameters are slightly adjusted.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci| Module       | Method/Attribute/Enumeration/Constant                                         | Change Type|
16e41f4b71Sopenharmony_ci| ------------- | ------------------------------------------------------------ | -------- |
17e41f4b71Sopenharmony_ci| @ohos.fileio  | **function** open(path: string, flags?: number, mode?: number, callback?: AsyncCallback<number>): void \| Promise<number>; | Deprecated    |
18e41f4b71Sopenharmony_ci| @ohos.fileio  | **function** openSync(path: string, flags?: number, mode?: number): number; | Deprecated    |
19e41f4b71Sopenharmony_ci| @ohos.file.fs | **function**  open(path: string, mode?: number, callback?: AsyncCallback<File>): void \| Promise<File>; | Added    |
20e41f4b71Sopenharmony_ci| @ohos.file.fs | **function** openSync(path: string, mode?: number): File;    | Added    |
21e41f4b71Sopenharmony_ci| @ohos.fileio  | **function** read(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: number; position?: number; }, callback?: AsyncCallback<ReadOut>): void \| Promise<ReadOut>; | Deprecated    |
22e41f4b71Sopenharmony_ci| @ohos.fileio  | **function** readSync(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: number; position?: number; }): number; | Deprecated    |
23e41f4b71Sopenharmony_ci| @ohos.file.fs | **function** read(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: number; }, callback?: AsyncCallback<number>): void \| Promise<number>; | Added    |
24e41f4b71Sopenharmony_ci| @ohos.file.fs | **function** readSync(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: number; }): number; | Added    |
25e41f4b71Sopenharmony_ci| @ohos.fileio  | **function** stat(path: string, callback?: AsyncCallback<Stat>): void \| Promise<Stat>; | Deprecated    |
26e41f4b71Sopenharmony_ci| @ohos.fileio  | **function** statSync(path: string): Stat;                   | Deprecated    |
27e41f4b71Sopenharmony_ci| @ohos.fileio  | **function** fstat(fd: number, callback?: AsyncCallback<Stat>): void \| Promise<Stat>; | Deprecated    |
28e41f4b71Sopenharmony_ci| @ohos.fileio  | **function** fstatSync(fd: number): Stat;                    | Deprecated    |
29e41f4b71Sopenharmony_ci| @ohos.file.fs | **function** stat(file: string \| number, callback?: AsyncCallback<Stat>): void \| Promise<Stat>; | Added    |
30e41f4b71Sopenharmony_ci| @ohos.file.fs | **function** statSync(file: string \| number): Stat;         | Added    |
31e41f4b71Sopenharmony_ci| @ohos.fileio  | **function** truncate(path: string, len?: number, callback?: AsyncCallback<void>): void \| Promise<void>; | Deprecated    |
32e41f4b71Sopenharmony_ci| @ohos.fileio  | **function** truncateSync(path: string, len?: number): void; | Deprecated    |
33e41f4b71Sopenharmony_ci| @ohos.fileio  | **function** ftruncate(fd: number, len?: number, callback?: AsyncCallback<void>): void \| Promise<void>; | Deprecated    |
34e41f4b71Sopenharmony_ci| @ohos.fileio  | **function** ftruncateSync(fd: number, len?: number): void;  | Deprecated    |
35e41f4b71Sopenharmony_ci| @ohos.file.fs | **function** truncate(file: string \| number, len?: number, callback?: AsyncCallback<void>): void \| Promise<void>; | Added    |
36e41f4b71Sopenharmony_ci| @ohos.file.fs | **function** truncateSync(file: string \| number, len?: number): void; | Added    |
37e41f4b71Sopenharmony_ci| @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    |
38e41f4b71Sopenharmony_ci| @ohos.fileio  | **function** writeSync(fd: number, buffer: ArrayBuffer \| string, options?: { offset?: number; length?: number; position?: number; encoding?: string; }): number; | Deprecated    |
39e41f4b71Sopenharmony_ci| @ohos.file.fs | **function** write(fd: number, buffer: ArrayBuffer \| string, options?: { offset?: number; length?: number; encoding?: string; }, callback?: AsyncCallback<number>): void \| Promise<void>; | Added    |
40e41f4b71Sopenharmony_ci| @ohos.file.fs | **function** writeSync(fd: number, buffer: ArrayBuffer \| string, options?: { offset?: number; length?: number; encoding?: string; }): number; | Added    |
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci**Adaptation Guide**
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ciThe original APIs use **@ohos.fileio**, which is imported as follows:
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci```js
47e41f4b71Sopenharmony_ciimport fileio from '@ohos.fileio';
48e41f4b71Sopenharmony_ci```
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ciThe new APIs use **@ohos.file.fs**, which is imported as follows:
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci```js
53e41f4b71Sopenharmony_ciimport fs from '@ohos.file.fs';
54e41f4b71Sopenharmony_ci```
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ciIn addition, exception handling needs to be adapted. Sample code for synchronous API exception handling is as follows:
57e41f4b71Sopenharmony_ci```js
58e41f4b71Sopenharmony_ciimport fs from '@ohos.file.fs'
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_citry {
61e41f4b71Sopenharmony_ci    let file = fs.openSync(path, fs.OpenMode.READ_ONLY);
62e41f4b71Sopenharmony_ci} catch (err) {
63e41f4b71Sopenharmony_ci    console.error("openSync errCode:" + err.code + ", errMessage:" + err.message);
64e41f4b71Sopenharmony_ci}
65e41f4b71Sopenharmony_ci```
66e41f4b71Sopenharmony_ciSample code for handling exceptions of the **promise** method of an asynchronous API:
67e41f4b71Sopenharmony_ci```js
68e41f4b71Sopenharmony_ciimport fs from '@ohos.file.fs'
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_citry {
71e41f4b71Sopenharmony_ci    let file = await fs.open(path, fs.OpenMode.READ_ONLY);
72e41f4b71Sopenharmony_ci} catch (err) {
73e41f4b71Sopenharmony_ci    console.error("open promise errCode:" + err.code + ", errMessage:" + err.message);
74e41f4b71Sopenharmony_ci}
75e41f4b71Sopenharmony_ci```
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ciSample code for handling exceptions of the **callback** method of an asynchronous API:
78e41f4b71Sopenharmony_ci```js
79e41f4b71Sopenharmony_ciimport fs from '@ohos.file.fs'
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_citry {
82e41f4b71Sopenharmony_ci    fs.open(path, fs.OpenMode.READ_ONLY, function(e, file){ // Asynchronous thread (such as system call) errors are obtained from the callback.
83e41f4b71Sopenharmony_ci        if (e) {
84e41f4b71Sopenharmony_ci            console.error("open in async errCode:" + e.code + ", errMessage:" + e.message);
85e41f4b71Sopenharmony_ci        }
86e41f4b71Sopenharmony_ci    });
87e41f4b71Sopenharmony_ci} catch (err) {// Errors (such as invalid parameters) of the main thread are obtained through try catch.
88e41f4b71Sopenharmony_ci    console.error("open callback errCode:" + err.code + ", errMessage:" + err.message);
89e41f4b71Sopenharmony_ci}
90e41f4b71Sopenharmony_ci```
91