Android存儲數(shù)據(jù)到本地文件-創(chuàng)新互聯(lián)

xml文件

我們提供的服務(wù)有:成都網(wǎng)站建設(shè)、網(wǎng)站制作、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、北湖ssl等。為上1000+企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的北湖網(wǎng)站制作公司
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="5dp"
 >

    <EditText
        android:id="@+id/qqnum"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
       	android:hint="請輸入QQ"
       	android:inputType="number"
        android:textSize="20dp"
        />
    <EditText 
        android:id="@+id/pass"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="請輸入密碼"
        android:inputType="textPassword"
        android:textSize="20dp"
        
        />
    <CheckBox 
        android:id="@+id/rem"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="記住密碼"
        
        />
    <Button 
        android:id="@+id/Login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="登錄"/>

</LinearLayout>

Utils

package com.example.android22filelogin;

import java.io.BufferedReader;
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.text.TextUtils;

public class Utils {
	public static boolean saveUserInfo(String username,String pwd){
		String data=username+"##"+pwd;
		String path="/data/data/com.example.android22filelogin/data.txt";
		try {
			FileOutputStream out=new FileOutputStream(path);
			out.write(data.getBytes());
			out.flush();
			out.close();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	public static Map<String,String> getUserInfo(){
		String path="/data/data/com.example.android22filelogin/data.txt";
		try {
			BufferedReader reader=new BufferedReader(new InputStreamReader(new FileInputStream(path)));
			String data=reader.readLine();
			if(!TextUtils.isEmpty(data))
			{
				String [] datas=data.split("##");
				Map<String, String> userinfo=new HashMap<String, String>();
				userinfo.put("number", datas[0]);
				userinfo.put("pwd", datas[1]);
				return userinfo;
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	
	
	
	
	
	
	

}

activity

public class MainActivity extends Activity implements OnClickListener {
	private EditText qqnum,pwd;
	private CheckBox rem;
	private Button but;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        qqnum=(EditText)findViewById(R.id.qqnum);
        pwd=(EditText)findViewById(R.id.pass);
        rem=(CheckBox)findViewById(R.id.rem);
        but=(Button)findViewById(R.id.Login);
        but.setOnClickListener(this);
        //回顯數(shù)據(jù)
        Map<String, String> userinfo=Utils.getUserInfo();
        if(userinfo!=null)
        {
        	qqnum.setText(userinfo.get("number"));
        	pwd.setText(userinfo.get("pwd"));
        }
    }

	@Override
	public void onClick(View v) {
		//記住號碼和密碼
		
		String num=qqnum.getText().toString();
		String password=pwd.getText().toString();
		if(TextUtils.isEmpty(num)||TextUtils.isEmpty(password))
		{
			Toast.makeText(this, "用戶名或密碼不能為空", Toast.LENGTH_LONG).show();
			return;
		}
		//判斷是否記住密碼
		if(rem.isChecked())
		{
			boolean isSuccess=Utils.saveUserInfo(num, password);
			Toast.makeText(this, isSuccess+"", Toast.LENGTH_LONG).show();
		}
		//登錄成功
		
	}


}

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

當(dāng)前題目:Android存儲數(shù)據(jù)到本地文件-創(chuàng)新互聯(lián)
網(wǎng)頁鏈接:http://bm7419.com/article34/diccpe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、網(wǎng)站收錄、虛擬主機(jī)、關(guān)鍵詞優(yōu)化、響應(yīng)式網(wǎng)站企業(yè)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司