달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
728x90
반응형

안드로이드 앱배포시 DB 배포.

앱배포시 DB배포는 안되므로,

하나의 방법중 하나인 웹으로부터 다운받게끔 한뒤 파일을 해당패키지로 복사한다.

 

해당 패키지의 디렉토리를 만들고, 파일을 생성해야 된다. 그렇치 않으면 두번 실행해야 파일이 제대로 쓰여진다.

 

private void downloadDB(HttpURLConnection conn, String FileName) {

 

            // 웹페이지에서 다운받은 db파일을 해당 패키지 db 저장한다.

            final String DIR ="/data/data/com.ludvan/databases/";

            final String PATH = DIR+ FileName;

            File fDir = new File(DIR);

            File f = new File(PATH);

 

            FileOutputStream fos = null;

            BufferedOutputStream bos = null;

            InputStream is = null;

            BufferedInputStream bis = null;

 

            try {

                  URL url = new URL("http://........db");

                  HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();

 

                  if(!fDir.exists()){

                        fDir.mkdir();

                  }

                  if (f.exists()) {

                        f.delete();

                        f.createNewFile();

                  }

                  is = httpConn.getInputStream();

                  bis = new BufferedInputStream(is);

 

                             

                  fos = new FileOutputStream(f);

                  bos = new BufferedOutputStream(fos);

 

                  int read = -1;

                  int len = conn.getContentLength();

                  byte[] buffer = new byte[len];

 

                  while ((read = bis.read(buffer, 0, 1024)) != -1) {

                        bos.write(buffer, 0, read);

                  }

                  bos.flush();     

                  Log.i(TAG, "write sucess");

            } catch (IOException e) {

                  // TODO Auto-generated catch block

                  Log.i(TAG, "file Write error");

            } finally {

                  try {

                        fos.close();

                        bos.close();

                        is.close();

                        bis.close();

                  } catch (IOException e) {

 

                  }

            }

      }// downloadDB

안드로이드 앱배포시 DB 배포.

앱배포시 DB배포는 안되므로,

하나의 방법중 하나인 웹으로부터 다운받게끔 한뒤 파일을 해당패키지로 복사한다.

 

해당 패키지의 디렉토리를 만들고, 파일을 생성해야 된다. 그렇치 않으면 두번 실행해야 파일이 제대로 쓰여진다.

 

private void downloadDB(HttpURLConnection conn, String FileName) {

 

            // 웹페이지에서 다운받은 db파일을 해당 패키지 db 저장한다.

            final String DIR ="/data/data/com.ludvan/databases/";

            final String PATH = DIR+ FileName;

            File fDir = new File(DIR);

            File f = new File(PATH);

 

            FileOutputStream fos = null;

            BufferedOutputStream bos = null;

            InputStream is = null;

            BufferedInputStream bis = null;

 

            try {

                  URL url = new URL("http://........db");

                  HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();

 

                  if(!fDir.exists()){

                        fDir.mkdir();

                  }

                  if (f.exists()) {

                        f.delete();

                        f.createNewFile();

                  }

                  is = httpConn.getInputStream();

                  bis = new BufferedInputStream(is);

 

                             

                  fos = new FileOutputStream(f);

                  bos = new BufferedOutputStream(fos);

 

                  int read = -1;

                  int len = conn.getContentLength();

                  byte[] buffer = new byte[len];

 

                  while ((read = bis.read(buffer, 0, 1024)) != -1) {

                        bos.write(buffer, 0, read);

                  }

                  bos.flush();     

                  Log.i(TAG, "write sucess");

            } catch (IOException e) {

                  // TODO Auto-generated catch block

                  Log.i(TAG, "file Write error");

            } finally {

                  try {

                        fos.close();

                        bos.close();

                        is.close();

                        bis.close();

                  } catch (IOException e) {

 

                  }

            }

      }// downloadDB

 

728x90
반응형
:
Posted by mapagilove