Android存儲數據到本地文件-創新互聯

xml文件

我們提供的服務有:成都網站建設、網站制作、微信公眾號開發、網站優化、網站認證、北湖ssl等。為上1000+企事業單位解決了網站和推廣的問題。提供周到的售前咨詢和貼心的售后服務,是有科學管理、有技術的北湖網站制作公司
<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);
        //回顯數據
        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();
		}
		//登錄成功
		
	}


}

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

當前題目:Android存儲數據到本地文件-創新互聯
網頁鏈接:http://m.kartarina.com/article34/diccpe.html

成都網站建設公司_創新互聯,為您提供企業網站制作網站收錄虛擬主機關鍵詞優化響應式網站企業建站

廣告

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

網站建設網站維護公司
主站蜘蛛池模板: 无码人妻精品一区二区三区夜夜嗨| 国产AV无码专区亚洲AV蜜芽| 国产日韩精品无码区免费专区国产| 精品人妻无码专区在中文字幕| 无码国产伦一区二区三区视频| 18精品久久久无码午夜福利| 亚洲一区AV无码少妇电影☆| 黄桃AV无码免费一区二区三区| 成人免费无码大片A毛片抽搐| 国产成人AV一区二区三区无码| 久久亚洲精品无码观看不卡| 久久AV无码精品人妻糸列| 自慰系列无码专区| 亚洲av永久无码天堂网| 亚洲中文字幕久久精品无码VA| 无码一区二区三区在线观看| 中文字幕乱码人妻无码久久 | 人妻丰满熟妇AV无码区免| 免费无码毛片一区二区APP| 人妻系列无码专区无码中出| 台湾无码AV一区二区三区| 精品无码成人久久久久久| 久久亚洲精品无码VA大香大香| 少妇性饥渴无码A区免费 | 无码少妇一区二区三区浪潮AV| YY111111少妇无码理论片| 人妻无码中文字幕免费视频蜜桃| 国产福利无码一区在线 | 亚洲AV无码成人网站久久精品大| 国产亚洲精品无码拍拍拍色欲 | 人妻AV中出无码内射| 天堂无码在线观看| 亚洲Av无码国产情品久久| 国产成A人亚洲精V品无码性色 | 国产精品无码一区二区三级| 精品人妻系列无码人妻免费视频| 久久久久亚洲精品无码网址| 国产成人综合日韩精品无码不卡| 国产亚洲精品无码拍拍拍色欲| 亚洲桃色AV无码| 亚洲AV无码专区在线亚|