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

相关推荐

  • 日语,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 日
  • bo.android应用:短息发送器

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

    2012 年 02 月 01 日
  • DNS挟持后续更新,问题解决了

    解决DNS挟持的办法就是投诉,不断投诉,上工信部投诉 上次提到,我这边的电信网络被挟持,具体原因就不多说了 可恨,我被DNS挟持了?打开京东默认跳转到推广链接 经过多方面的投诉,现在问题终于解决,很多电信工程…

    闲话杂谈 2016 年 09 月 09 日
  • java压缩高清图片,解决JAVA压缩图片变红、变黑、变色问题

    突发奇想,想改善一下图片,当然第一时间想到的是自身技能java 那么java怎样才能高清压缩图片呢?下面的例子可以帮助你 import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Font; import jav…

    闲话杂谈 2016 年 06 月 02 日
  • 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 日
  • iphone 验机

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

    闲话杂谈 2011 年 08 月 08 日
  • 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 日
  • java中HashMap,LinkedHashMap,TreeMap,HashTable的区别

    java中HashMap,LinkedHashMap,TreeMap,HashTable的区别 java为数据结构中的映射定义了一个接口java.util.Map;它有四个实现类,分别是HashMap Hashtable LinkedHashMap 和TreeMap Map主要用于存储健值对,根据键得到…

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

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

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