dongzhang1864 2012-03-07 05:47
浏览 37

将带有用户名和密码的文件保存到SD卡并读取它是否存在于数据库中

guys i two edit text values which i need to save to text file into sdcard which will be basically username and password.

After storing it i need to read that file and check whether the username and password which is in text file is in database or not.

I am using php and mysql as database.

Code for saving the file to sdcard:

try {
            File myFile = new File("/sdcard/mysdfile.txt");
            myFile.createNewFile();
            FileOutputStream fOut = new FileOutputStream(myFile);
            OutputStreamWriter myOutWriter = 
                                    new OutputStreamWriter(fOut);
            myOutWriter.append(txtData.getText());
            myOutWriter.close();
            fOut.close();
            Toast.makeText(getBaseContext(),
                    "Done writing SD 'mysdfile.txt'",
                    Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            Toast.makeText(getBaseContext(), e.getMessage(),
                    Toast.LENGTH_SHORT).show();
        }

how to acheive this please help

  • 写回答

1条回答 默认 最新

  • doushan2311 2012-03-07 09:29
    关注

    To read username and password from file you can try something like this and change it accordint to what you need:

     int rme = 0;    
     FileInputStream fstream = new FileInputStream("file path");
     DataInputStream in = new DataInputStream(fstream);
     BufferedReader br = new BufferedReader(new InputStreamReader(in));
     String str;
    
    // read data accoridng your need in my case this is how i did it in java.
    
     while ((str = br.readLine()) != null) {
      rememberme= str.toString();
      rme=Integer.parseInt(rememberme);
      str = br.readLine();
      uname=str.toString();
      str = br.readLine();
      password=str.toString();        
     } 
    //rme=Integer.parseInt(uname);
    

    return rme;

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序