Android进阶(七)数据存储_"file file = new file(getexternalfilesdir(null),

最后

好了,这就是整理的前端从入门到放弃的学习笔记,还有很多没有整理到,我也算是边学边去整理,后续还会慢慢完善,这些相信够你学一阵子了。

做程序员,做前端工程师,真的是一个学习就会有回报的职业,不看出身高低,不看学历强弱,只要你的技术达到应有的水准,就能够得到对应的回报。

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

学习从来没有一蹴而就,都是持之以恒的,正所谓活到老学到老,真正懂得学习的人,才不会被这个时代的洪流所淘汰。

InputStream in = getResources().openRawResource(R.raw.bbi); 
//在\Test\res\raw\bbi.txt,
  int length = in.available();       
  byte [] buffer = new byte[length];        
  in.read(buffer);         
  //res = EncodingUtils.getString(buffer, “UTF-8”);
  //res = EncodingUtils.getString(buffer, “UNICODE”); 
  res = EncodingUtils.getString(buffer, “BIG5”); 
  //依bbi.txt的编码类型选择合适的编码,如果不调整会乱码
  in.close();            
  }catch(Exception e){ 
     e.printStackTrace();         
  } 
//把得到的内容显示在TextView上
myTextView.setText(res);
1.1.2从asset中获取文件并读取数据(资源文件只能读不能写)

assets目录下,称为原生文件,这类文件在被打包成apk文件时是不会进行压缩的,android使用AssetManager对assets文件进行访问,通过getResources().getAssets()获得AssetManager,

其有一个open()方法可以根据用户提供的文件名,返回一个InputStream对象供用户使用。

eg:
//文件名字
String fileName = “yan.txt”; 
String res=“”; 
try{ 
 // \Test\assets\yan.txt这里有这样的文件存在
//通过getResources().getAssets()获得AssetManager
 InputStream in = getResources().getAssets().open(fileName);
//返回读取的大概字节数
int length = in.available();         
byte [] buffer = new byte[length];        
in.read(buffer);            
res = EncodingUtils.getString(buffer, “UTF-8”);     
}catch(Exception e){ 
  e.printStackTrace();         
 }
1.2访问设备存储相当于API工作目录
1.2.1调用context.openFileInput() 返回 FileInputStream读文件
1.2.2通过调用context.openFileOutput() 返回FileOutputStream写文件
//写文件在./data/data/com.tt/files/下面
openFileOutput()参数
filename 文件名
int mode 操作模式 MODE_PRIVATE 默认,创建或替换该文件名的文件作为应用程序私有文件。
         MODE_APPEND,MODE_WORLD_READABLE , MODE_WORLD_WRITEABLE,
eg:
String FILENAME = “hello_file”;
String string = “hello world!”;
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();
1.3保存缓存文件

如果您想缓存一些数据,而不是它长期存放,可以把文件保存为缓存文件;保存为缓存文件时,当设备内部存储空间不足,系统可能会删除这些缓存文件恢复空间;我们应该限制缓存空间的大小;

当用户卸载应用程序时,这些文件将被删除。

使用方法:
//获取保存文件系统的目录绝对路径
getFilesDir(); 
//在存储空间中创建或打开一个目录
getDir();
//删除存储文件
deleteFile();
//返回应用程序保存文件列表
fileList();
2使用外部存储
2.1.1检测外部存储状态:
Environment.getExternalStorageState()
boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
    // We can read and write the media
    mExternalStorageAvailable = mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
    // We can only read the media
    mExternalStorageAvailable = true;
    mExternalStorageWriteable = false;
} else {
    // Something else is wrong. It may be one of many other states, but all we need
    //  to know is we can neither read nor write
    mExternalStorageAvailable = mExternalStorageWriteable = false;
}
2.1.2访问外部存储

API8以上,使用getExternalFilesDir()打开一个外部存储文件目录,这个方法需传递一个指定类型目录的参数,如:DIRECTORY_MUSIC和DIRECTORY_RINGTONES,为空返回应用程序文件根目录;

此方法可以根据指定的目录类型创建目录,该文件为应用程序私有,如果卸载应用程序,目录将会一起删除。

API7一下,使用getExternalStorageDirectory(), 打开外部存储文件根目录 ,你的文件写入到如下目录中:/Android/data/<package_name>/files/
eg:
void createExternalStoragePrivateFile() {
    // Create a path where we will place our private file on external storage.
    File file = new File(getExternalFilesDir(null), “DemoFile.jpg”);
    try {
        // Very simple code to copy a picture from the application’s
        // resource into the external file.  Note that this code does
        // no error checking, and assumes the picture is small (does not
        // try to copy it in chunks).  Note that if external storage is
        // not currently mounted this will silently fail.
        InputStream is = getResources().openRawResource(R.drawable.balloons);
        OutputStream os = new FileOutputStream(file);
        byte[] data = new byte[is.available()];
        is.read(data);
        os.write(data);
        is.close();
        os.close();
    } catch (IOException e) {
        // Unable to create file, likely because external storage is not currently mounted.
        Log.w(“ExternalStorage”, “Error writing " + file, e);
    }
}
void deleteExternalStoragePrivateFile() {
    // Get path for the file on external storage. If external
    // storage is not currently mounted this will fail.
    File file = new File(getExternalFilesDir(null), “DemoFile.jpg”);
    if (file != null) {
        file.delete();
    }
}
boolean hasExternalStoragePrivateFile() {
    // Get path for the file on external storage.  If external
    // storage is not currently mounted this will fail.
    File file = new File(getExternalFilesDir(null), “DemoFile.jpg”);
    if (file != null) {
        return file.exists();
    }
    return false;
}
2.1.3保存为共享文件
如果想将文件保存为不为应用程序私有,在应用程序卸载时不被删除,需要将文件保存到外部存储的公共目录上,这些目录在存储设备根目录下;如:音乐,图片,铃声等。
API8以上,使用 getExternalStoragePublicDirectory(),传入一个公共目录的类型参数,如DIRECTORY_MUSIC, DIRECTORY_PICTURES, DIRECTORY_RINGTONES等, 目录不存在时这个方法会为你创建目录。
API7一下,使用 getExternalStorageDirectory() 打开存储文件根目录,保存文件到下面的目录中:
Music,Podcasts,Ringtones,Alarms,Notifications,Pictures,Movies,Download。
eg:
void createExternalStoragePublicPicture() {
    // Create a path where we will place our picture in the user’s public pictures directory. 
    File path = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES);
    File file = new File(path, “DemoPicture.jpg”);
    try {
        // Make sure the Pictures directory exists.
        path.mkdirs();
        InputStream is = getResources().openRawResource(R.drawable.balloons);
        OutputStream os = new FileOutputStream(file);
        byte[] data = new byte[is.available()];
        is.read(data);
        os.write(data);
        is.close();
        os.close();
    } catch (IOException e) {
         Log.w(“ExternalStorage”, “Error writing " + file, e);
    }
}
void deleteExternalStoragePublicPicture() {
    // Create a path where we will place our picture in the user’s
    // public pictures directory and delete the file.  If external
    // storage is not currently mounted this will fail.
    File path = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES);
    File file = new File(path, “DemoPicture.jpg”);
    file.delete();
}
boolean hasExternalStoragePublicPicture() {
    // Create a path where we will place our picture in the user’s
    // public pictures directory and check if the file exists.  If
    // external storage is not currently mounted this will think the
    // picture doesn’t exist.
    File path = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES);
    File file = new File(path, “DemoPicture.jpg”);
    return file.exists();
}
2.1.4保存缓存文件
API8以上,使用getExternalCacheDir() 打开存储目录保存文件,如卸载应用程序,缓存文件将自动删除,在应用程序运行期间你可以管理这些缓存文件,如不在使用可以删除以释放空间。
API7以下,使用getExternalStorageDirectory() 打开缓存目录,缓存文件保存在下面的目录中:
/Android/data/<package_name>/cache/
<package_name> 你的java包名如 “com.example.android.app”.
2.1.5读写文件
提示:openFileOutput是在raw里编译过的访问设备存储,FileOutputStream是任何文件都可以
访问sdcard直接实例FileOutputStream对象,而访问存储设备文件通过openFileOutput返回FileOutputStream对象对数据操作。
2.1.6 sdcard中去读文件
示例:
String fileName = “/sdcard/Y.txt”;
//也可以用String fileName = “mnt/sdcard/Y.txt”;
String res=””;     
try{ 
FileInputStream fin = new FileInputStream(fileName);
//FileInputStream fin = openFileInput(fileName);  
//用这个就不行了,必须用FileInputStream
    int length = fin.available(); 
    byte [] buffer = new byte[length]; 
    fin.read(buffer);     
    res = EncodingUtils.getString(buffer, “UTF-8”);

基础学习:

前端最基础的就是 HTML , CSS 和 JavaScript 。

网页设计:HTML和CSS基础知识的学习

HTML是网页内容的载体。内容就是网页制作者放在页面上想要让用户浏览的信息,可以包含文字、图片、视频等。

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

CSS样式是表现。就像网页的外衣。比如,标题字体、颜色变化,或为标题加入背景图片、边框等。所有这些用来改变内容外观的东西称之为表现。

动态交互:JavaScript基础的学习

JavaScript是用来实现网页上的特效效果。如:鼠标滑过弹出下拉菜单。或鼠标滑过表格的背景颜色改变。还有焦点新闻(新闻图片)的轮换。可以这么理解,有动画的,有交互的一般都是用JavaScript来实现的。

入背景图片、边框等。所有这些用来改变内容外观的东西称之为表现。

[外链图片转存中…(img-84K9wCQC-1715771510629)]

动态交互:JavaScript基础的学习

JavaScript是用来实现网页上的特效效果。如:鼠标滑过弹出下拉菜单。或鼠标滑过表格的背景颜色改变。还有焦点新闻(新闻图片)的轮换。可以这么理解,有动画的,有交互的一般都是用JavaScript来实现的。

[外链图片转存中…(img-x3bBqiTW-1715771510630)]

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
分析一下这个json {&quot;name&quot;:&quot;12312&quot;,&quot;project_id&quot;:&quot;87156&quot;,&quot;project_name&quot;:&quot;上上下下左左右右baba与聚法科技(长春)有限公司与公司、证券、保险、票据等有关的民事纠纷&quot;,&quot;client&quot;:&quot;[{&quot;type&quot;:&quot;自然人&quot;,&quot;customer_id&quot;:&quot;80236&quot;,&quot;customer_name&quot;:&quot;上上下下左左右右baba&quot;}]&quot;,&quot;sign_date&quot;:&quot;2023-06-06&quot;,&quot;expire_date&quot;:&quot;2023-06-21&quot;,&quot;subject_amount&quot;:&quot;123&quot;,&quot;contract_amount&quot;:&quot;123&quot;,&quot;charge_method&quot;:&quot;一次性,分阶段,风险,计&quot;,&quot;equity_amount&quot;:&quot;13811&quot;,&quot;amount_info&quot;:&quot;[{&quot;type&quot;:&quot;一次性&quot;,&quot;pay_date&quot;:&quot;2023-07-03&quot;,&quot;charge_amount&quot;:&quot;12&quot;},{&quot;type&quot;:&quot;分阶段&quot;,&quot;pay_date&quot;:&quot;2023-06-13&quot;,&quot;charge_amount&quot;:&quot;123&quot;,&quot;is_satisfy&quot;:&quot;是&quot;,&quot;pay_condition&quot;:&quot;12312&quot;},{&quot;type&quot;:&quot;风险&quot;,&quot;pay_date&quot;:&quot;&quot;,&quot;charge_amount&quot;:&quot;&quot;,&quot;is_satisfy&quot;:&quot;是&quot;,&quot;pay_condition&quot;:&quot;123&quot;,&quot;basic_amount&quot;:&quot;123&quot;,&quot;risk_amount&quot;:&quot;12&quot;,&quot;object_amount&quot;:&quot;123123&quot;,&quot;object&quot;:&quot;赔偿金&quot;,&quot;risk_prop&quot;:&quot;13213&quot;,&quot;member&quot;:&quot;&quot;,&quot;rate&quot;:&quot;&quot;,&quot;hours&quot;:&quot;&quot;},{&quot;type&quot;:&quot;计&quot;,&quot;member_id&quot;:&quot;392159&quot;,&quot;member&quot;:&quot;曹野&quot;,&quot;rate&quot;:&quot;11&quot;,&quot;hours&quot;:&quot;1231&quot;}]&quot;,&quot;seal_person&quot;:&quot;123&quot;,&quot;seal_type&quot;:&quot;律所公章,法人名章,财务章&quot;,&quot;seal_num&quot;:&quot;123&quot;,&quot;file_path&quot;:&quot;[{&quot;title&quot;:&quot;导入错误数据 (15).xls&quot;,&quot;path&quot;:&quot;382585/1686381522542/导入错误数据 (15).xls&quot;,&quot;size&quot;:&quot;91136&quot;},{&quot;title&quot;:&quot;3.txt&quot;,&quot;path&quot;:&quot;382585/1686561731102/3.txt&quot;,&quot;size&quot;:44078}]&quot;,&quot;remark&quot;:&quot;123123&quot;} 并使用php转换成字符串
最新发布
06-13
这是一个包含多个键值对的 JSON 对象。其中包括合同的一些基本信息,如名称、项目 ID、签订日期、到期日期、合同金额、收费方式、盖章人、盖章类型、盖章数量、文件路径和备注等。其中一些键的值是 JSON 数组,需要进一步解析。 以下是将该 JSON 对象转换成字符串的 PHP 代码: ```php $json = '{&quot;name&quot;:&quot;12312&quot;,&quot;project_id&quot;:&quot;87156&quot;,&quot;project_name&quot;:&quot;上上下下左左右右baba与聚法科技(长春)有限公司与公司、证券、保险、票据等有关的民事纠纷&quot;,&quot;client&quot;:&quot;[{&quot;type&quot;:&quot;自然人&quot;,&quot;customer_id&quot;:&quot;80236&quot;,&quot;customer_name&quot;:&quot;上上下下左左右右baba&quot;}]&quot;,&quot;sign_date&quot;:&quot;2023-06-06&quot;,&quot;expire_date&quot;:&quot;2023-06-21&quot;,&quot;subject_amount&quot;:&quot;123&quot;,&quot;contract_amount&quot;:&quot;123&quot;,&quot;charge_method&quot;:&quot;一次性,分阶段,风险,计&quot;,&quot;equity_amount&quot;:&quot;13811&quot;,&quot;amount_info&quot;:&quot;[{&quot;type&quot;:&quot;一次性&quot;,&quot;pay_date&quot;:&quot;2023-07-03&quot;,&quot;charge_amount&quot;:&quot;12&quot;},{&quot;type&quot;:&quot;分阶段&quot;,&quot;pay_date&quot;:&quot;2023-06-13&quot;,&quot;charge_amount&quot;:&quot;123&quot;,&quot;is_satisfy&quot;:&quot;是&quot;,&quot;pay_condition&quot;:&quot;12312&quot;},{&quot;type&quot;:&quot;风险&quot;,&quot;pay_date&quot;:&quot;&quot;,&quot;charge_amount&quot;:&quot;&quot;,&quot;is_satisfy&quot;:&quot;是&quot;,&quot;pay_condition&quot;:&quot;123&quot;,&quot;basic_amount&quot;:&quot;123&quot;,&quot;risk_amount&quot;:&quot;12&quot;,&quot;object_amount&quot;:&quot;123123&quot;,&quot;object&quot;:&quot;赔偿金&quot;,&quot;risk_prop&quot;:&quot;13213&quot;,&quot;member&quot;:&quot;&quot;,&quot;rate&quot;:&quot;&quot;,&quot;hours&quot;:&quot;&quot;},{&quot;type&quot;:&quot;计&quot;,&quot;member_id&quot;:&quot;392159&quot;,&quot;member&quot;:&quot;曹野&quot;,&quot;rate&quot;:&quot;11&quot;,&quot;hours&quot;:&quot;1231&quot;}]&quot;,&quot;seal_person&quot;:&quot;123&quot;,&quot;seal_type&quot;:&quot;律所公章,法人名章,财务章&quot;,&quot;seal_num&quot;:&quot;123&quot;,&quot;file_path&quot;:&quot;[{&quot;title&quot;:&quot;导入错误数据 (15).xls&quot;,&quot;path&quot;:&quot;382585/1686381522542/导入错误数据 (15).xls&quot;,&quot;size&quot;:&quot;91136&quot;},{&quot;title&quot;:&quot;3.txt&quot;,&quot;path&quot;:&quot;382585/1686561731102/3.txt&quot;,&quot;size&quot;:44078}]&quot;,&quot;remark&quot;:&quot;123123&quot;}'; $data = json_decode(str_replace('&quot;', '&quot;', $json), true); $str = ''; foreach ($data as $key => $value) { if (is_array($value)) { $value = json_encode($value); } $str .= $key . ':' . $value . ','; } $str = '{' . rtrim($str, ',') . '}'; echo $str; ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值