源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

java文件操作之java写文件简单示例

  • 时间:2021-01-06 12:29 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:java文件操作之java写文件简单示例
代码很简单,直接上代码,大家参考使用吧
[u]复制代码[/u] 代码如下:
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;   }  } }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部