新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OS 分布式文件服務(wù)開發(fā)指導(dǎo)
場景介紹

成都創(chuàng)新互聯(lián)公司主營孝昌網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,app軟件開發(fā)公司,孝昌h5小程序開發(fā)搭建,孝昌網(wǎng)站營銷推廣歡迎孝昌等地區(qū)企業(yè)咨詢
應(yīng)用可以通過分布式文件服務(wù)實(shí)現(xiàn)多個(gè)設(shè)備間的文件共享,設(shè)備 1 上的應(yīng)用A創(chuàng)建了分布式文件 a,設(shè)備 2 上的應(yīng)用A能夠通過分布式文件服務(wù)讀寫設(shè)備 1 上的文件 a。
接口說明
分布式文件兼容 POSIX 文件操作接口,應(yīng)用使用 Context.getDistributedDir() 接口獲取目錄后,可以直接使用 libc 或 JDK 訪問分布式文件。
| 接口名 | 描述 |
|---|---|
| Context.getDistributedDir() | 獲取文件的分布式目錄 |
開發(fā)步驟
應(yīng)用可以通過 Context.getDistributedDir() 接口獲取屬于自己的分布式目錄,然后通過 libc 或 JDK 接口,在該目錄下創(chuàng)建、刪除、讀寫文件或目錄。
- 設(shè)備 1 上的應(yīng)用 A 創(chuàng)建文件 hello.txt,并寫入內(nèi)容"Hello World"。
Context context;
... // context初始化
File distDir = context.getDistributedDir();
String filePath = distDir + File.separator + "hello.txt";
FileWriter fileWriter = new FileWriter(filePath,true);
fileWriter.write("Hello World");
fileWriter.close();- 設(shè)備 2 上的應(yīng)用 A 通過 Context.getDistributedDir() 接口獲取分布式目錄。
- 設(shè)備 2 上的應(yīng)用 A 讀取文件 hello.txt。
FileReader fileReader = new FileReader(filePath);
char[] buffer = new char[1024];
fileReader.read(buffer);
fileReader.close();
System.out.println(buffer); 分享文章:創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OS 分布式文件服務(wù)開發(fā)指導(dǎo)
文章來源:http://fisionsoft.com.cn/article/dhggsdi.html


咨詢
建站咨詢
