android中xml文件在哪,如何在android中创建xml文件

伙计们,我有一个问题,当我们在android中编写xml时,我的代码给出了一个异常作为权限被拒绝。任何人都可以知道它将如何被移除。如何在android中创建xml文件

package com.ex.createXml;

import android.app.Activity;

import android.os.Bundle;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import org.xmlpull.v1.XmlSerializer;

import android.os.Environment;

import android.util.Log;

import android.util.Xml;

import android.widget.TextView;

public class createXml extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

File newxmlfile = new File("/data/new.xml");

try{

newxmlfile.createNewFile();

}catch(IOException e)

{

Log.e("IOException", "Exception in create new File(");

}

FileOutputStream fileos = null;

try{

fileos = new FileOutputStream(newxmlfile);

}catch(FileNotFoundException e)

{

Log.e("FileNotFoundException",e.toString());

}

XmlSerializer serializer = Xml.newSerializer();

try{

serializer.setOutput(fileos, "UTF-8");

serializer.startDocument(null, Boolean.valueOf(true));

serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);

serializer.startTag(null, "root");

serializer.startTag(null, "Child1");

serializer.endTag(null, "Child1");

serializer.startTag(null, "Child2");

serializer.attribute(null, "attribute", "value");

serializer.endTag(null, "Child2");

serializer.startTag(null, "Child3");

serializer.text("Some text inside child 3");

serializer.endTag(null,"Child3");

serializer.endTag(null,"root");

serializer.endDocument();

serializer.flush();

fileos.close();

//TextView tv = (TextView)findViewById(R.);

}catch(Exception e)

{

Log.e("Exception","Exception occured in wroting");

}

}

}

+5

请不要再次提出同样的问题。 –

2011-03-03 14:44:44

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值