sitelink1 http://doraeul.tistory.com/38 
sitelink2  
sitelink3  

파일시스템에 파일 생성하여 데이터 저장하기

 

package com.andr;

 

import java.io.BufferedWriter;

import java.io.OutputStreamWriter;

 

import android.app.Activity;

import android.os.Bundle;

import android.util.Log;

import android.widget.TextView;

 

public class main extends Activity{

 @Override

 public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.main);

 

  TextView t=(TextView) findViewById(R.id.TextView01);

  BufferedWriter br=null;

  try {

 

   br=new BufferedWriter(new OutputStreamWriter(openFileOutput("data1.txt", MODE_WORLD_WRITEABLE)));

   br.append("안녕하세요");

   br.append("반갑습니다");

   t.setText("파일이 정상적으로 생성되었습니다.");

  } catch (Exception e) {

   Log.i("IO", "File Input Error");

   t.setText("오류");

  }finally {

   try {

   if(br!=null) br.close();

   } catch (Exception e2) {e2.printStackTrace();}

  }

 }

}

//main.xml에는 TextView 1개 TextView가 있어야 한다.

 

 

 

 

 

파일 시스템에 파일 불러오기 예:(위에 저장한 data1.txt 파일을 불러온다.)

 

package com.andr;

 

import java.io.BufferedReader;

import java.io.InputStreamReader;

 

import android.app.Activity;

import android.os.Bundle;

import android.util.Log;

import android.widget.TextView;

 

public class main extends Activity{

 @Override

 public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.main);

 

  TextView t=(TextView) findViewById(R.id.TextView01);

  BufferedReader br=null;

  try {

 

   br=new BufferedReader(new InputStreamReader(openFileInput("data1.txt")));

   String msg=br.readLine();

  t.setText(msg);

  } catch (Exception e) {

   Log.i("IO", "File Input Error");

  }finally {

   try { 

   if(br!=null) br.close();

   } catch (Exception e2) {e2.printStackTrace();}

  }

 }

}

//main.xml에는 TextView 1개 TextView가 있어야 한다.

번호 제목 글쓴이 날짜 조회 수
68 TTS 를 위한 스마트폰 설정 및 TTS 샘플 file 황제낙엽 2019.02.16 575
67 Creating swipe views with tabs file 황제낙엽 2019.02.10 209
66 [번역] 안드로이드 ViewPager 를 이용한 수평 화면 전환 file 황제낙엽 2019.02.09 175
65 동적 레이아웃 생성과 자동 줄바꿈 구현 file 황제낙엽 2018.12.26 435
64 qemu-system-~.exe 의 작동이 중지되었습니다 file 황제낙엽 2018.11.27 180
63 Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'. file 황제낙엽 2018.11.27 169
62 Error:Minimum supported Gradle version is 4.1. 황제낙엽 2018.11.27 190
61 No toolchains found in the NDK toolchains folder for ABI 황제낙엽 2018.11.27 165
60 [성공샘플] HttpURLConnection 을 이용하여 JSON 데이터 보내기 예제 황제낙엽 2018.11.10 750
59 [Android] 네이버 음성합성(TTS) API 사용해 보기 file 황제낙엽 2018.11.01 299
58 [Android] TTS (Text To Speech) API 샘플 코드 file 황제낙엽 2018.11.01 294
57 Google Cloud API 설정법 file 황제낙엽 2018.11.01 169
56 AsyncTask 사용하기 황제낙엽 2018.10.29 170
55 Volley 소개 및 관련 링크 황제낙엽 2018.10.29 168
54 AsyncTask 를 이용한 HttpURLConnection 사용법 [1] 황제낙엽 2018.10.20 178
53 HttpURLConnection 을 이용하여 JSON 데이터 보내기 예제 [1] file 황제낙엽 2018.10.20 234
52 STT 학습 링크 모음 (sample link) 황제낙엽 2018.10.11 760
51 코틀린(Kotlin) 학습용 링크 모음 황제낙엽 2018.10.11 265
50 저장소 파일 불러올 때 권한 요청 설정 file 황제낙엽 2018.08.21 1851
» 안드로이드 파일시스템에 파일 생성하여 데이터 저장, 불러오기 예제 황제낙엽 2018.08.21 178