android_往sd中写入文件
2017-03-27 14:41
148 查看
if( Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED) )
{
File dir = Environment.getExternalStorageDirectory();
try {
File file = new File(dir, "jiaoz.txt");
FileOutputStream fos
= new FileOutputStream(file);
fos.write( "鬼吹灯这部小说来源于真实的咧比故事。。".getBytes() );
fos.flush();
fos.close();
fos = null;
} catch (IOException e) {
e.printStackTrace();
}
}
} else if (view.getId() == R.id.button2) {
String a = "";
if( Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED) )
{
File dir = Environment.getExternalStorageDirectory();
try {
File file = new File(dir, "jiaoz1.txt");
FileInputStream fis
= new FileInputStream(file);
int count = fis.available();
byte[] bytes = new byte[count];
int len=0;
while((len=fis.read(bytes))!=-1){
System.out.println(len);
a=a+new String(bytes,0,len);
}
aa.setText(a);
fis.close();
fis = null;
} catch (IOException e) {
e.printStackTrace();
}
} }
else if (view.getId() == R.id.button3) {
String a = "";
if( Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED) )
{
File dir = Environment.getExternalStorageDirectory();
try {
File file = new File(dir, "jiaoz2.txt");
FileInputStream fis
= new FileInputStream(file);
int count = fis.available();
byte[] bytes = new byte[count];
int len=0;
while((len=fis.read(bytes))!=-1){
System.out.println(len);
a=a+new String(bytes,0,len);
}
aa.setText(a);
fis.close();
fis = null;
} catch (IOException e) {
e.printStackTrace();
}
} }
if( Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED) )
{
File dir = Environment.getExternalStorageDirectory();
try {
File file = new File(dir, "jiaoz.txt");
FileOutputStream fos
= new FileOutputStream(file);
fos.write( "鬼吹灯这部小说来源于真实的咧比故事。。".getBytes() );
fos.flush();
fos.close();
fos = null;
} catch (IOException e) {
e.printStackTrace();
}
}
} else if (view.getId() == R.id.button2) {
String a = "";
if( Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED) )
{
File dir = Environment.getExternalStorageDirectory();
try {
File file = new File(dir, "jiaoz1.txt");
FileInputStream fis
= new FileInputStream(file);
int count = fis.available();
byte[] bytes = new byte[count];
int len=0;
while((len=fis.read(bytes))!=-1){
System.out.println(len);
a=a+new String(bytes,0,len);
}
aa.setText(a);
fis.close();
fis = null;
} catch (IOException e) {
e.printStackTrace();
}
} }
else if (view.getId() == R.id.button3) {
String a = "";
if( Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED) )
{
File dir = Environment.getExternalStorageDirectory();
try {
File file = new File(dir, "jiaoz2.txt");
FileInputStream fis
= new FileInputStream(file);
int count = fis.available();
byte[] bytes = new byte[count];
int len=0;
while((len=fis.read(bytes))!=-1){
System.out.println(len);
a=a+new String(bytes,0,len);
}
aa.setText(a);
fis.close();
fis = null;
} catch (IOException e) {
e.printStackTrace();
}
} }
Environment.MEDIA_MOUNTED) )
{
File dir = Environment.getExternalStorageDirectory();
try {
File file = new File(dir, "jiaoz.txt");
FileOutputStream fos
= new FileOutputStream(file);
fos.write( "鬼吹灯这部小说来源于真实的咧比故事。。".getBytes() );
fos.flush();
fos.close();
fos = null;
} catch (IOException e) {
e.printStackTrace();
}
}
} else if (view.getId() == R.id.button2) {
String a = "";
if( Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED) )
{
File dir = Environment.getExternalStorageDirectory();
try {
File file = new File(dir, "jiaoz1.txt");
FileInputStream fis
= new FileInputStream(file);
int count = fis.available();
byte[] bytes = new byte[count];
int len=0;
while((len=fis.read(bytes))!=-1){
System.out.println(len);
a=a+new String(bytes,0,len);
}
aa.setText(a);
fis.close();
fis = null;
} catch (IOException e) {
e.printStackTrace();
}
} }
else if (view.getId() == R.id.button3) {
String a = "";
if( Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED) )
{
File dir = Environment.getExternalStorageDirectory();
try {
File file = new File(dir, "jiaoz2.txt");
FileInputStream fis
= new FileInputStream(file);
int count = fis.available();
byte[] bytes = new byte[count];
int len=0;
while((len=fis.read(bytes))!=-1){
System.out.println(len);
a=a+new String(bytes,0,len);
}
aa.setText(a);
fis.close();
fis = null;
} catch (IOException e) {
e.printStackTrace();
}
} }
if( Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED) )
{
File dir = Environment.getExternalStorageDirectory();
try {
File file = new File(dir, "jiaoz.txt");
FileOutputStream fos
= new FileOutputStream(file);
fos.write( "鬼吹灯这部小说来源于真实的咧比故事。。".getBytes() );
fos.flush();
fos.close();
fos = null;
} catch (IOException e) {
e.printStackTrace();
}
}
} else if (view.getId() == R.id.button2) {
String a = "";
if( Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED) )
{
File dir = Environment.getExternalStorageDirectory();
try {
File file = new File(dir, "jiaoz1.txt");
FileInputStream fis
= new FileInputStream(file);
int count = fis.available();
byte[] bytes = new byte[count];
int len=0;
while((len=fis.read(bytes))!=-1){
System.out.println(len);
a=a+new String(bytes,0,len);
}
aa.setText(a);
fis.close();
fis = null;
} catch (IOException e) {
e.printStackTrace();
}
} }
else if (view.getId() == R.id.button3) {
String a = "";
if( Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED) )
{
File dir = Environment.getExternalStorageDirectory();
try {
File file = new File(dir, "jiaoz2.txt");
FileInputStream fis
= new FileInputStream(file);
int count = fis.available();
byte[] bytes = new byte[count];
int len=0;
while((len=fis.read(bytes))!=-1){
System.out.println(len);
a=a+new String(bytes,0,len);
}
aa.setText(a);
fis.close();
fis = null;
} catch (IOException e) {
e.printStackTrace();
}
} }
相关文章推荐
- 在android中如何从服务器上下载文件 并写入到 sdcard上去
- android中将数据写入手机内存和sdcard中的文件
- Android 从网络上下载文件以及写入到SDcard里面
- android中将数据写入手机内存和sdcard中的文件
- android中将数据写入手机内存和sdcard中的文件
- 【Android】向sdcard中写入文件
- android 文件读写,sdcard写入
- Android写入文件到sdcard中
- Android中没有插入SD情况下的文件写入和读取方法
- Android中没有插入SD情况下的文件写入和读取
- 输入流文件写入SDCARD
- Android追加写入文件的几种方法
- 安装APK文件到Android模拟器和Android sdcard的使用
- android操作sdcard中的多媒体文件(二)——音乐列表的更新
- android操作sdcard中的多媒体文件(一)——音乐列表的制作
- android 删除sdcard中文件命令
- 安装APK文件到Android模拟器和Android sdcard的使用
- 安装APK文件到Android模拟器和Android sdcard的使用
- Android文件、内存、SDCard管理常用工具类、方法
- android WebView 控件加载本地sdcard中html文件图片的问题