Minggu, 28 September 2014

[SQL] Java

package com.phonegap1;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.cordova.DroidGap;

import com.phonegap1.R;


import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class MyPhoneGapActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try
{
String pName = this.getClass().getPackage().getName();
this.copy("tes.db","/data/data/"+pName+"/databases/");
}
catch (IOException e)
{
e.printStackTrace();
}
super.loadUrl("file:///android_asset/www/index.html",3000);
}
void copy(String file, String folder) throws IOException {
File CheckDirectory;
CheckDirectory = new File(folder);
if (!CheckDirectory.exists())
{
CheckDirectory.mkdir();
}

InputStream in = getApplicationContext().getAssets().open(file);
OutputStream out = new FileOutputStream(folder+file);

// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len; while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
in.close(); out.close();

}
}

Tidak ada komentar:

Posting Komentar