Vous êtes sur la page 1sur 4

Created by Simpo

PDFO
Creator
ProMY
(unregistered
version)
TNH NHT NGH
TRUNG TM
TO MNG
I http://www.simpopdf.com
TC O TO CA MICROSOFT TI VIT NAM
105 B Huyn Thanh Quan, Q3, TP. HCM
Tel: 3.9322.735-0913.735.906 Fax: 3.9322.734 Web: nhatnghe.com

Bui 9: File input - output


BT1: Xy dng ng dng Android n gin c file cadao.txt v xut ra mn
hnh

Created by Simpo
PDFO
Creator
ProMY
(unregistered
version)
TNH NHT NGH
TRUNG TM
TO MNG
I http://www.simpopdf.com
TC O TO CA MICROSOFT TI VIT NAM
105 B Huyn Thanh Quan, Q3, TP. HCM
Tel: 3.9322.735-0913.735.906 Fax: 3.9322.734 Web: nhatnghe.com

Chp file cadao.txt vo trong folder assets.

Sau vit code n gin


package com.android.demo_readfiletext;
import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Demo_readfiletextActivity extends Activity {
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// i tm
tv=(TextView) findViewById(R.id.textView1);
// code x l
try{
InputStream input = getAssets().open("cadao.txt");
int size = input.available();
byte[] buffer = new byte[size];
input.read(buffer);
input.close();
String text = new String(buffer);
text=text.replace("\r\n", "\n");
tv.setText(text);
} catch (Exception ex){
tv.setText("Khong the doc file cadao.txt");
}
}
}

Created by Simpo
PDFO
Creator
ProMY
(unregistered
version)
TNH NHT NGH
TRUNG TM
TO MNG
I http://www.simpopdf.com
TC O TO CA MICROSOFT TI VIT NAM
105 B Huyn Thanh Quan, Q3, TP. HCM
Tel: 3.9322.735-0913.735.906 Fax: 3.9322.734 Web: nhatnghe.com

BT2: Xy dng ng dng Android n gin c file danhngon.txt v hin th


ra mn hnh tng cu danh ngn khi touch trn mn hnh.

Created by Simpo
PDFO
Creator
ProMY
(unregistered
version)
TNH NHT NGH
TRUNG TM
TO MNG
I http://www.simpopdf.com
TC O TO CA MICROSOFT TI VIT NAM
105 B Huyn Thanh Quan, Q3, TP. HCM
Tel: 3.9322.735-0913.735.906 Fax: 3.9322.734 Web: nhatnghe.com

BT3: Xy dng ng dng Android Truyn Ci n gin c file truyencuoi.txt


v hin th ra mn hnh tng cu truyn ci.
Yu cu :
- Tiu truyn c mu
- Ni dung truyn c mu xanh
- Trn cng giao din c 4 button : u, Trc, Sau, Cui cho php duyt
xem tng truyn.
- Cu trc file truyn ci

Vous aimerez peut-être aussi