DialogInterface dialog, int id) { // TODO Auto-generated method stub dialog.dismiss(); } }).setNegativeButton("退出", new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog, int id) { // TODO Auto-generated method stub dialog.dismiss(); } }).show(); } });
4.业务代码
代码
/* * 保存文件 */ public static void save(OutputStream outStream, String content) throws Exception { // 写入数据 outStream.write(content.getBytes()); outStream.close(); } /* * 读取文件 */ public static String read(InputStream inStream) throws Exception { // 字节流 ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = -1; //获取字节数据 while ((len = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, len); } //得到字节数据 byte[] data = outStream.toByteArray(); outStream.close(); inStream.close(); return new String(data); }
四、小结
这个例子只是简单的操作文件的读写,很多地方都不够完善,希望有兴趣的网友们可以互相交流下~~~