且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从内部存储Android应用程序Excel文件访问

更新时间:2022-12-21 11:55:54

有关读写使用的 Apache的POI库

要一些样本的例子是有机器人通过读写Excel工作表

To some sample example is there for android through read and write excel sheet

1)创建/读取一个Excel文件中的Andr​​oid

2)的Andr​​oid阅读使用EXCEL写入文件的Apache POI

有关资产,以SD卡按照此链接一>或者使用code。

For Assets to SDcard Follow this link Or use this code.

    package com.paresh.copyfileassetstoAssets;

    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;

    import android.app.Activity;
    import android.content.res.AssetManager;
    import android.os.Bundle;
    import android.os.Environment;
    import android.util.Log;

    public class CopyFileAssetsToSDCardActivity extends Activity 
    {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

           CopyAssets();
        }

        private void CopyAssets() {
            AssetManager assetManager = getAssets();
            String[] files = null;
            try {
                files = assetManager.list("Files");
            } catch (IOException e) {
                Log.e("tag", e.getMessage());
            }

            for(String filename : files) {
                System.out.println("File name => "+filename);
                InputStream in = null;
                OutputStream out = null;
                try {
                  in = assetManager.open("Files/"+filename);   // if files resides inside the "Files" directory itself
                  out = new FileOutputStream(Environment.getExternalStorageDirectory().toString() +"/" + filename);
                  copyFile(in, out);
                  in.close();
                  in = null;
                  out.flush();
                  out.close();
                  out = null;
                } catch(Exception e) {
                    Log.e("tag", e.getMessage());
                }
            }
        }
        private void copyFile(InputStream in, OutputStream out) throws IOException {
            byte[] buffer = new byte[1024];
            int read;
            while((read = in.read(buffer)) != -1){
              out.write(buffer, 0, read);
            }
        }
    }