国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

java文件操作之java寫文件簡單示例

2019-11-26 15:36:01
字體:
來源:轉載
供稿:網友

代碼很簡單,直接上代碼,大家參考使用吧

復制代碼 代碼如下:

package com.it.login.service;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

import android.content.Context;

public class LoginService {
 /**
  * 保存文件
  * @param context 上下文
  * @param username
  * @param password
  * @return
  */

 public static boolean saveUserInfo(Context context,String username,String password){
  File file=new File(context.getFilesDir(),"user.bat"); //在當前包下,創建文件
  try {
   FileOutputStream fis = new FileOutputStream(file);
   fis.write((username+"##"+password).getBytes());
   fis.close();

   return true;
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
   return false;
  }

 }
 /**
  * 回顯用戶名  密碼
  * @param context
  * @return
  */
 public static Map<String,String> getUserInfo(Context context){
  File file=new File(context.getFilesDir(),"user.bat");
  try {
   Map<String,String> map=new HashMap<String, String>();
   FileInputStream fis = new FileInputStream(file);
   BufferedReader br=new BufferedReader(new InputStreamReader(fis));
   String str=br.readLine();
   String[] infos=str.split("##");
   map.put("username", infos[0]);
   map.put("password", infos[1]);

   return map;
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();

   return null;
  }
 }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 肥东县| 彭泽县| 伊吾县| 花垣县| 抚顺县| 宁乡县| 嘉禾县| 广灵县| 彰化县| 江华| 綦江县| 三都| 松原市| 安宁市| 双柏县| 天水市| 新兴县| 淮南市| 武冈市| 天长市| 汉寿县| 宝应县| 石渠县| 财经| 临城县| 罗源县| 静海县| 重庆市| 临江市| 洮南市| 彭泽县| 丹江口市| 温宿县| 大同市| 太白县| 台州市| 丰顺县| 新乐市| 抚远县| 鹤山市| 塘沽区|