bo.android应用系列:文件创建

目前功能:创建一个文件,并写入内容
========================
截图:

 bo.android应用系列:文件创建

 

 

 bo.android应用系列:文件创建

 

 

 

 bo.android应用系列:文件创建

 

 

========================

部分代码:

/**
 * <p>
 * 业务层<br/>
 * 2012-02-09
 * </p>
 * @author Bo
 *
 */
public class FileService {
	/**
	 * context对象
	 */
	private Context context;
	/**
	 * 构造函数,是的使用此类必须传一个context进来
	 * @param context
	 */
	public FileService(Context context){
		this.context = context;
	}
	/**
	 * 保存内容
	 * @param fileName 文件名称
	 * @param fileContent 文件内容
	 * @throws Exception
	 */
	public void save(String fileName, String fileContent) throws Exception{
	//  MODE_PRIVATE 表示私有的,只能被当前应该使用
		FileOutputStream outStream = context.openFileOutput(fileName, context.MODE_PRIVATE);
		outStream.write(fileContent.getBytes());
	}
}

/**
 * <p>
 * 文件的创建与保存</br/>
 * 2012-02-09
 * </p>
 * @author bo
 *
 */
public class MainFileActivity extends Activity {
	private FileService service ;
	private static final String TAG = "MainFileActivity";
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //实例化
        service = new FileService(this);
        
        Button button = (Button)this.findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				EditText fileNameText = (EditText) findViewById(R.id.fileName);
				EditText fileContentText = (EditText) findViewById(R.id.fileContent);
				//文件名
				String fileName = fileNameText.getText().toString();
				//内容
				String fileContent = fileContentText.getText().toString();
				try {
					service.save(fileName, fileContent);
					Toast.makeText(MainFileActivity.this, R.string.success, 1).show();
				} catch (Exception e) {
					Log.e(TAG, e.toString());
					Toast.makeText(MainFileActivity.this, R.string.error, 1).show();
				}
			}
		});
    }
}

 

文章来源于网络或者作者投稿,若有侵权请联系删除,作者:老钟,如若转载,请注明出处:https://www.laoz.net/221.html

(0)
老钟
上一篇 2012 年 02 月 08 日 下午 4:40
下一篇 2012 年 02 月 16 日 下午 1:06

相关推荐

  • 在URLHttpConnection中使用代理服务器

    原文出处: 在URLHttpConnection中使用代理服务器 作者: Jet Mah from Java堂 在JDK5之前如果在URLHttpConnection中使用代理服务器的话,只要在URL.openConnection()之前加入以下代码就可以: Properties prop = Sys…

    闲话杂谈 2011 年 08 月 25 日
  • Access restriction: The type Reflection is not accessible due to restrictio

        解决方法: Windows -> Preferences -> Java -> Compiler -> Errors/Warnings -> Deprecated and trstricted API -> Forbidden reference (access rules): -> change to warning

    闲话杂谈 2011 年 12 月 02 日
  • bo.android应用:短息发送器

    视频完毕,参照教程,仿做了个发送短信的 同样需要启动两个模拟器测试 ===========================   =========================== 部分代码: /**  * <p>  * 短信发送器<br/>  * 2012-02-01  * …

    2012 年 02 月 01 日
  • HashMap与ConcurrentHashMap性能测试

    http://blog.csdn.net/liuzhengkang/article/details/2916829 http://blog.sina.com.cn/s/blog_605f5b4f0100qsio.html http://hi.baidu.com/fallen9/blog/item/690e963d56471209bba1670a.html http://www.xue5.com/…

    闲话杂谈 2011 年 08 月 30 日
  • eclipse下java.lang.OutOfMemoryError: Java heap space的解决办法

    目前我没使用到tomcat,紧java项目, 设置如下 1,从Intalled JREs里修改;window->Preferences->Java->Installed JREs,选择当前的JRE,然后edit它;在新窗口里设置Default VM Arguments为 -Xms128M -Xmx…

    闲话杂谈 2011 年 08 月 15 日
  • 可恨,我被DNS挟持了?打开京东默认跳转到推广链接

    打开京东跳转到推广链接~ 我现在用的是电信网络,经过多方面测试,我怀疑是电信DNS挟持,其实很早之前就发现在浏览器上面输入网址: JD.COM,就会默认跳转到推广的链接,只不过一直没有跟它较劲,今天突发神经,坚…

    2016 年 07 月 01 日
  • iphone 验机

    你拿到机子查看sn码是否一致,就是机盒背面的sn序列号与卡槽上的sn序列号和手机-设置-通用-关于本机 里 面的序列号一样,如果有电脑,连接电脑,itunes上出现的序列号也应该一致。在有条件就用电脑上网,登陆 https…

    闲话杂谈 2011 年 08 月 08 日
  • 哪个银行信用卡最好用?哪个银行信用卡最好

    四大国有商业银行: 建设银行: 优点: 1、免首年年费,刷三次免次年年费; 2、短信服务免费; 3、取现手续费仅0.5%; 4、挂失手续费50元; 5、有直接针对有车族信用卡,只要有1.4排量以上的车均能轻松办卡。 缺点…

    闲话杂谈 2011 年 10 月 09 日
  • java编程中提升性能的一些方法【转】

    最近的机器内存又爆满了,出了新增机器内存外,还应该好好review一下我们的代码,有很多代码编写过于随意化,这些不好的习惯或对程序语言的不了解是应该好好打压打压了。 下面是参考网络资源和总结一些在java编程中…

    闲话杂谈 2011 年 08 月 16 日
  • 老钟非常LOVE的一些电影

    挚爱、视觉和听觉都超级一流的电影: 钢铁侠 Iron Man(2008.04.30) 无敌浩克 The Incredible Hulk(2008.08.20) 钢铁侠2 Iron Man 2(2010.04.25) 雷神托尔 Thor(2011.05.02) 美国队长 Captain America: The …

    2014 年 04 月 22 日