标签:
public void bt3(View v){ try { //从内存写入文件 //1.得到内部存储目录 File file=getFilesDir(); String s=file.getAbsolutePath(); Toast.makeText(MainActivity.this, "path="+s, Toast.LENGTH_SHORT).show(); //2.用输出流写入文件 FileOutputStream fos=openFileOutput("test.txt",MODE_PRIVATE); //3.写入文件内容 PrintStream ps=new PrintStream(fos); String ss=et.getText().toString(); ps.println(ss); ps.print("测试"); ps.close(); fos.close(); Toast.makeText(MainActivity.this, "保存成功", Toast.LENGTH_SHORT).show();} catch (Exception e){ } } public void bt4(View v){ try { //输入流 FileInputStream fis=openFileInput("test.txt"); //定义byte[] byte []b=new byte[1024]; int i; //循环读 String str1=""; while ((i=fis.read(b))>0){ str1 =new String(b,0,i); } et2.setText(str1); fis.close(); } catch (Exception e){ } }
标签:
原文地址:http://www.cnblogs.com/storm47/p/5533592.html