[Android] XML 파일 생성
File newxmlfile = new File(Environment.getExternalStorageDirectory()+"/new.xml");
try{
newxmlfile.createNewFile();
}catch(IOException e){
Log.e("IOException", "exception in createNewFile() method");
}
//we have to bind the new file with a FileOutputStream
FileOutputStream fileos = null;
try{
fileos = new FileOutputStream(newxmlfile);
}catch(FileNotFoundException e){
Log.e("FileNotFoundException", "can't create FileOutputStream");
}
//we create a XmlSerializer in order to write xml data
XmlSerializer serializer = Xml.newSerializer();
try {
//we set the FileOutputStream as output for the serializer, using UTF-8 encoding
serializer.setOutput(fileos, "UTF-8");
//Write <?xml declaration with encoding (if encoding not null) and standalone flag (if standalone not null)
serializer.startDocument(null, Boolean.valueOf(true));
//set indentation option
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
//start a tag called "root"
serializer.startTag(null, "root");
//i indent code just to have a view similar to xml-tree
serializer.startTag(null, "child1");
serializer.endTag(null, "child1");
serializer.startTag(null, "child2");
//set an attribute called "attribute" with a "value" for
serializer.attribute(null, "attribute", "value");
serializer.endTag(null, "child2");
serializer.startTag(null, "child3");
//write some text inside
serializer.text("some text inside child3");
serializer.endTag(null, "child3");
serializer.endTag(null, "root");
serializer.endDocument();
//write xml data into the FileOutputStream
serializer.flush();
//finally we close the file stream
fileos.close();
} catch (Exception e) {
Log.e("Exception","error occurred while creating xml file");
}
출처 : http://www.shop-wiz.com/document/android/execise_linkage_web_xml_create
'프로그래밍 > Android' 카테고리의 다른 글
[Android] WebView(웹뷰) 속성 (0) | 2015.03.26 |
---|---|
[Android] android 파일 다운로드 후 hwp파일 열기! (0) | 2015.03.26 |
[Android] if 값 비교가 제대로 안되는 경우 ex: if(a == b) (0) | 2015.03.16 |
[Android] Android 기본탐색기가 없다!! (0) | 2015.01.23 |
I/Choreographer(5855): Skipped 99 frames! The application may be doing too much work on its main thread. (0) | 2015.01.22 |
[Android] if 값 비교가 제대로 안되는 경우 ex: if(a == b)
이클립스에서 자바언어로 비교문이 제대로 안됨.
원인 : 특히나 문자열 같은 경우 a == b로 잘 안됨
해결
String a = "check";
String b = "check";
if(a == b) // X
if(a.equals(b)) // O
아래꺼도 문자열 비교!
-------------- 추가 --------------
a.CompareToString인가.. 있길래 추가함
if(a.CompareToString(b) == 0) // a 와 b 가 같으면 0의 값이 출력되나봄.
지금 이클립스 안키고 있어요 .. ㅜㅜ 정확한건 컨트롤 + 스페이스바 눌러서 자동완성 뭐지 그거.. 어시스트 써서 보세요!
'프로그래밍 > Android' 카테고리의 다른 글
[Android] android 파일 다운로드 후 hwp파일 열기! (0) | 2015.03.26 |
---|---|
[Android] XML 파일 생성 (0) | 2015.03.18 |
[Android] Android 기본탐색기가 없다!! (0) | 2015.01.23 |
I/Choreographer(5855): Skipped 99 frames! The application may be doing too much work on its main thread. (0) | 2015.01.22 |
android.os.NetworkOnMainThreadException 에러! (0) | 2015.01.10 |
[Android] Android 기본탐색기가 없다!!
Android는 기본 탐색기가 사용되지 않는다. (확인불가. 100% 정확한건 아님.)
* 해결방법
1. 탐색기 프로그램을 사용한다.
2. 탐색기를 만들어 쓴다.
* 부가설명
한꺼번에 설명하자면,
탐색기를 사용한 어플들이 많이 있다.
핸드폰에서 sdcard의 폴더들을 탐색. 하위 폴더 및 파일들을 찾아서 리스트뷰로 뿌려주고, 선택 시 파일인지 폴더인지 확인해서 알맞게 사용함. ( 1번같은경우 자동으로 생략 가능함. 편리함. 다만 직접 탐색기를 설치해야된다는 점 등 불편한 점이 있을 수 있음. )
그걸 이용해서 파일 이름과 경로를 리턴해서 업로드에 사용함.
'프로그래밍 > Android' 카테고리의 다른 글
[Android] android 파일 다운로드 후 hwp파일 열기! (0) | 2015.03.26 |
---|---|
[Android] XML 파일 생성 (0) | 2015.03.18 |
[Android] if 값 비교가 제대로 안되는 경우 ex: if(a == b) (0) | 2015.03.16 |
I/Choreographer(5855): Skipped 99 frames! The application may be doing too much work on its main thread. (0) | 2015.01.22 |
android.os.NetworkOnMainThreadException 에러! (0) | 2015.01.10 |
I/Choreographer(5855): Skipped 99 frames! The application may be doing too much work on its main thread.
I/Choreographer(5855): Skipped 99 frames! The application may be doing too much work on its main thread.
현재 에러 찾는중.동영상 업로드 하는중인데, 메인UI에서 쓰레드를 사용하려 해서 스킵된듯..
에러 해결.
- 원인
동영상 업로드 시 메인 UI에서도 사용가능하도록
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
를 써줬는데도 프레임이 초과함.
- 해결
그냥 다른곳에서 쓰레드 사용. (어신크테스크 씀)
'프로그래밍 > Android' 카테고리의 다른 글
[Android] android 파일 다운로드 후 hwp파일 열기! (0) | 2015.03.26 |
---|---|
[Android] XML 파일 생성 (0) | 2015.03.18 |
[Android] if 값 비교가 제대로 안되는 경우 ex: if(a == b) (0) | 2015.03.16 |
[Android] Android 기본탐색기가 없다!! (0) | 2015.01.23 |
android.os.NetworkOnMainThreadException 에러! (0) | 2015.01.10 |
android.os.NetworkOnMainThreadException 에러!
android.os.NetworkOnMainThreadException 이 에러가 발생했다.
주로 메인UI에서 쓰레드를 쓰려고 할 경우 뜨는 에러.
해결방법
1. 메인UI 외 다른 부분에서 쓰레드 만들어서 사용.
2. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy); 사용!
2번예시
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_name);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
'프로그래밍 > Android' 카테고리의 다른 글
[Android] android 파일 다운로드 후 hwp파일 열기! (0) | 2015.03.26 |
---|---|
[Android] XML 파일 생성 (0) | 2015.03.18 |
[Android] if 값 비교가 제대로 안되는 경우 ex: if(a == b) (0) | 2015.03.16 |
[Android] Android 기본탐색기가 없다!! (0) | 2015.01.23 |
I/Choreographer(5855): Skipped 99 frames! The application may be doing too much work on its main thread. (0) | 2015.01.22 |