第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

安卓存儲(chǔ)資源

標(biāo)簽:
Android

本地永久存储字符串

复制代码

 1 public void saveAsFile(String content) 2     { 3         String headPath=android.os.Environment.getExternalStorageDirectory()+"/aaa/mdoor.txt"; 4         FileWriter fwriter=null; 5         try { 6             fwriter=new FileWriter(headPath); 7             fwriter.write(content); 8         } catch (IOException e) { 9             // TODO Auto-generated catch block10             e.printStackTrace();11         }12         try {13             fwriter.flush();14             fwriter.close();15         } catch (IOException e) {16             // TODO Auto-generated catch block17             e.printStackTrace();18         }19     }20     public void readFile()21     {22         String headPath=android.os.Environment.getExternalStorageDirectory()+"/aaa/mdoor.txt";23         File file = new File(headPath);24         BufferedReader reader=null;25         try {26             reader= new BufferedReader(new FileReader(file));27             String tempString =null;28             29                 while((tempString=reader.readLine())!=null)30                 {31                     Log.e("paytest","json"+tempString );32                     content=tempString;33                 }34             35             reader.close();36         } catch (Exception e) {37             // TODO Auto-generated catch block38             e.printStackTrace();39         }finally{40             if(reader!=null)41             {42                 try {43                     reader.close();44                 } catch (IOException e) {45                     // TODO Auto-generated catch block46                     e.printStackTrace();47                 }48             }49         }50     }

复制代码

从网上下载图片信息然后存储到本地

复制代码

  1 public void savePIC()  2     {  3         Bitmap bitmap = null;  4         try {  5               6             bitmap =getPicture("https://qmby.feefoxes.com/h5/newlegend/version1/wechatapp/sharetest.jpg");  7         } catch (Exception e) {  8             // TODO Auto-generated catch block  9             e.printStackTrace(); 10             Log.e("paytest", "aaa"); 11         } 12         try { 13             saveBitmap(bitmap); 14         } catch (Exception e) { 15             // TODO Auto-generated catch block 16             e.printStackTrace(); 17             Log.e("paytest", "hhh"); 18         } 19     } 20     public void saveBitmap(Bitmap bitmap) throws IOException { 21         //更改的名字 22         String imageName="wwwwa"+".jpg"; 23          24         String headPath=android.os.Environment.getExternalStorageDirectory()+"/aaa"; 25         Log.e("headPath", headPath); 26         Log.e("headPath", headPath); 27             File headDir=new File(headPath); 28             if(!headDir.exists()){ 29                 headDir.mkdirs(); 30             } 31             System.out.println(headPath+"\n"+headDir);    
 32             FileOutputStream headFos=null; 33             File headFile=null; 34             try{ 35                 //重命名并保存 36                 headFile=new File(headPath,imageName); 37                 headFile.createNewFile(); 38                  39                 headFos=new FileOutputStream(headFile); 40                 bitmap.compress(CompressFormat.JPEG, 100, headFos); 41                 headFos.flush(); 42                  43             }catch(Exception e){ 44                 e.printStackTrace(); 45             }finally{ 46                 if(headFos!=null){ 47                     try { 48                         headFos.close(); 49                     } catch (IOException e) { 50                         e.printStackTrace(); 51                     } 52                 } 53             } 54          55     } 56     /* 57      * 从服务器端得到图片 58      */ 59     public Bitmap getPicture(String path) throws Exception 60     { 61         Bitmap bm=null; 62         URL url; 63         try {  
 64             SSLSocketFactory.getSocketFactory().setHostnameVerifier(new AllowAllHostnameVerifier()); 65             url = new URL(path);//创建URL对象   66             URLConnection conn=url.openConnection();//获取URL对象对应的连接   67             conn.connect();//打开连接   68             InputStream is=conn.getInputStream();//获取输入流对象   69              /*String filepath=null; 70              if(numberPic==1) 71              { 72                  filepath="tempDir"+numberPic+".png"; 73              }else if(numberPic==2) 74              { 75                  filepath="tempDir"+numberPic+".jpg"; 76              } 77              byte[]data =readInputStream(is); 78               79              File imageFile =new File(filepath); 80              81             FileOutputStream outStream = new FileOutputStream(imageFile); 82              83             outStream.write(data); 84              85              86             Log.e("data", ""+outStream); 87             Log.e("data", ""+outStream); 88             */ 89             bm=BitmapFactory.decodeStream(is);//根据输入流对象创建Bitmap对象  
 90 //            outStream.close(); 91 //            is.close(); 92         } catch (MalformedURLException e1) {  
 93             e1.printStackTrace();//输出异常信息  94             Log.e("paytest",""+"url"); 95         }catch (Exception e) {  
 96             e.printStackTrace();//输出异常信息   97             Log.e("paytest",""+"bb"); 98         }  
 99         return bm;100     }

复制代码

原文出处:https://www.cnblogs.com/jian-dan-ai-boke/p/9609919.html

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消