一些写入 读出操作


 Process p = Runtime.getRuntime().exec("su");//转到root权限
                                              OutputStream os = p.getOutputStream();
                                             
                                              os.write("mkdir /cache/\n".getBytes());
                                             
                                              //cp 路径/cache/update.zip && rm 路径 && rm 路径.md5sum
                                              os.write(("cp " + mUpdateInfo.getFilePath() + " /cache/update.zip && rm " +
                                                      mUpdateInfo.getFilePath() + " && rm " + mUpdateInfo.getFilePath() +
                                                      ".md5sum\n").getBytes());

                                              os.write("mkdir /cache/recovery/\n".getBytes());
                                              os.write("echo 'boot-recovery' >/cache/recovery/command\n".getBytes());
                                              if (pref.doNandroidBackup())
                                                      os.write("echo '--nandroid'  >> /cache/recovery/command\n".getBytes());
                                              String cmd = "echo '--update_package=/cache/update.zip' >> /cache/recovery/command\n";
                                              os.write(cmd.getBytes());
                                              os.write("reboot recovery\n".getBytes());
                                              os.flush();
这是,update那个工程里,更换rom的脚本。


  • try {
                FileOutputStream f1 = context.openFileOutput("info.txt", 0);
                OutputStreamWriter w = new OutputStreamWriter(f1);
                w.write(mRes.getString(R.string.PREF_LAST_UPDATE_CHECK)+"="+d.getTime());
                w.flush();
                w.close();
                f1.close();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
这是写入文件

  • FileInputStream fis = context.openFileInput("info.txt");
            InputStreamReader reader = new InputStreamReader(fis);
            BufferedReader r = new BufferedReader(reader);
            String sb="";
            try {
                sb = r.readLine();
                Log.d(TAG, sb);
                sb = sb.split("=")[1];//用=作标志,分成两端,取第二段
                time = new Date(Long.valueOf(sb));
            } catch (IOException e) {
                e.printStackTrace();
            }
这是读出文件

  •         try
            {
                URL url = new URL("http://192.168.4.195:8080/change.zip");
                InputStream is = url.openStream();
                OutputStream os = openFileOutput("change.zip", 0);
                byte[] buff = new byte[1024];
                int hasRead = 0;
                while((hasRead = is.read(buff)) > 0)
                {
                    os.write(buff, 0, hasRead);
                }
                is.close();
                os.close();
            } catch (Exception e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
                System.out.println("wrong");
            }
其实是个下载操作
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值