but_read.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
File path = Environment.getExternalStorageDirectory();
File file = new File(path, "0321Test.txt");
try {
FileInputStream in = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(in, "GBK");
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
Toast.makeText(MainActivity.this, "未发现SD卡",
Toast.LENGTH_SHORT).show();
}
}
});
but_write.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
File path = Environment.getExternalStorageDirectory();
File file = new File(path, "0321Test.txt");
try {
FileOutputStream out = new FileOutputStream(file, true);
out.write("hello,world!!".getBytes());
out.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});