专业网站建设品牌,十四年专业建站经验,服务6000+客户--广州京杭网络
免费热线:400-683-0016      微信咨询  |  联系我们

鸿蒙系统大文件夹4个怎么设置_服务器

当前位置:网站建设 > 技术支持
资料来源:网络整理       时间:2023/3/9 3:26:48       共计:3666 浏览

鸿蒙系统大文件夹4个怎么设置?

自定义文件夹以及文件存储位置,放在resources/rawfile文件下面:

自定义文件夹中文件读取方式有2种:

第一种方式:

String filePath = String.format(“assets/entry/resources/rawfile/api/v1/users/%s”, “page=1.json”)

%s为固定的必须要加

InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(filePath );

第二种

数据流的读取

BufferedReader bufferedReader = null;

try {

StringBuilder stringBuilder = new StringBuilder();

if(inputStream == null) {

return null;

}

bufferedReader = new BufferedReader(new InputStreamReader(inputStream));

String str;

boolean isFirst = true;

while ((str = bufferedReader.readLine()) != null) {

if (isFirst)

isFirst = false;

else

stringBuilder.append(’\n’);

stringBuilder.append(str);

}

return stringBuilder.toString();

} catch (IOException e) {

System.out.print("JsonMockServer: Error opening asset " + name);

} finally {

if (bufferedReader != null) {

try {

bufferedReader.close();

} catch (IOException e) {

System.out.print("JsonMockServer: Error closing asset " + name);

}

}

}

第二种方式读取

ResourceManager resourceManager = getApplicationContext().getResourceManager();

RawFileEntry rawFileEntry = resourceManager.getRawFileEntry(fileName);

InputStream inStream=rawFileEntry.openRawFile();

if(inStream=null){

HiLog.error(LABEL_LOG,"inStream=null");

}else{

HiLog.error(LABEL_LOG,“inStream==”+inStream.toString());

}

int len = 0;

byte[] data = new byte[1024];

while ((len = inStream.read(data)) != -1) {

outputStream.write(data, 0, len);

}

} catch (FileNotFoundException e) {

e.printStackTrace();

HiLog.error(LABEL_LOG,“FileNotFoundException==”+e.toString());

} catch (IOException e) {

e.printStackTrace();

}

String content=new String(outputStream.toByteArray()

图片流的加载

ImageSource.SourceOptions sourceOptions = new ImageSource.SourceOptions();

sourceOptions.formatHint = “image/jpg”;

ImageSource imageSource = ImageSource.create(outputStream.toByteArray(), sourceOptions);

ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions();

decodingOptions.desiredSize = new Size(0, 0);

decodingOptions.desiredRegion = new Rect(0, 0, 0, 0);

decodingOptions.desiredPixelFormat = PixelFormat.ARGB_8888;

PixelMap pixelMap = imageSource.createPixelmap(decodingOptions);

Image testIcon.setPixelMap(pixelMap);

版权说明:
本网站凡注明“广州京杭 原创”的皆为本站原创文章,如需转载请注明出处!
本网转载皆注明出处,遵循行业规范,如发现作品内容版权或其它问题的,请与我们联系处理!
欢迎扫描右侧微信二维码与我们联系。
·上一条:hp传真机怎么连接电话线接收传真_服务器 | ·下一条:ok和go中o发音相同吗_java

Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有    粤ICP备16019765号 

广州京杭网络科技有限公司 版权所有