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

相关推荐

  • Android Please execute ‘adb uninstall com.ims.poc.ui’ in a shell.

    [2010-03-23 11:57:49 - Poc]Re-installation failed due to different application signatures. [2010-03-23 11:57:49 - Poc]You must perform a full uninstall of the application. WARNING: This will remove t…

    闲话杂谈 2012 年 01 月 30 日
  • 哪个银行信用卡最好用?哪个银行信用卡最好

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

    闲话杂谈 2011 年 10 月 09 日
  • 日语,50音

    偶尔一个机会,需要整理一下日语50音(中文应该是音标)   あ(a) い(i) う(u) え(e) お(o) か(ka) き(ki) く(ku) け(ke) こ(ko) さ(sa) し(shi) す(su) せ(se) そ(so) た(ta) ち(chi) つ(tsu) て(te) と(to) …

    闲话杂谈 2012 年 03 月 01 日
  • 天猫发票问题,注意事项

    天猫发票这个基本的规则真的大家要熟读 往往犯错导致犯规的就是这个问题,下面和大家分享一下规则 开发票不收费 (不收税点不加钱)可以开普通发票,也可以开增值税发票买家付了多少钱就开多少钱,…

    闲话杂谈 2014 年 02 月 14 日
  • iphone 验机

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

    闲话杂谈 2011 年 08 月 08 日
  • Eclipse中导入工程提示:invalid project description 解决办法

    打开工程目录下的 .project文件, 把<name>标签中的文字改成自己的工程名

    闲话杂谈 2012 年 02 月 08 日
  • Eclipse快捷键大全(转载)

    Ctrl+1 快速修复(最经典的快捷键,就不用多说了) Ctrl+D: 删除当前行 Ctrl+Alt+↓ 复制当前行到下一行(复制增加) Ctrl+Alt+↑ 复制当前行到上一行(复制增加) Alt+↓ 当前行和下面一行交互位置(特别实用,可以省去先剪切,…

    闲话杂谈 2011 年 12 月 19 日
  • 天猫客服应该注意的事项,转自互联网

    网上看到的,本身自己也想收集一些规则,然后归纳总结出来的,既然网上有了,就直接拿过来用,出处忘记是哪里了,如果下次找到再更新文章!天猫不同于集市,淘宝对于天猫商城店铺管理要比C店严格的多了,很多时候都…

    闲话杂谈 2013 年 08 月 19 日
  • java 日期与毫秒转换,计算指定日期后N天

    最近写一些工具类中,遇到一些日期转换的问题,特意把方法分享,其还有很大的改进空间 /** * 把毫秒转化为日期<br/> * 转化后格式为 yyyy-MM-dd HH:mm:ss * * @param ms * @return 日期字符串 */ public stat…

    闲话杂谈 2011 年 09 月 23 日
  • 老钟非常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 日