在Dropbox Uri中保存文件

时间:2018-01-08 17:34:55

标签: java android file uri android-contentresolver

我需要知道如何保存Dropbox中的文件(修改后)。

我有dropbox URI:“ content://com.dropbox.android.FileCache/filecache/cf9e7a01-dcee-47b3-9e4e-8c78e470d313

我一直在测试的代码如下:

ContentResolver cr = context.getContentResolver();

OutputStream out= null;
try {
        out = cr.openOutputStream(uri);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    wb.write(out); //look at the rest of the code fragments to understand

  //RESULT --> dropboxfile not UPDATED

我不知道如何通过我的excel传递FileOutputStream来创建Dropbox文件(在OutputStream中?)

我要保存的文件是excel表,在保存之前,我用以下代码填写它:

 Workbook wb = new HSSFWorkbook();
 //... 
 //code to fill wb
 //...
 File fileDest = new File(path, "aux.xls");
    FileOutputStream os = null;
    try {
        os = new FileOutputStream(fileDest);
        wb.write(os);

我认为可以使用“ContentResolver”来完成,这是我用来从dropbox读取文件的,但我不知道如何使用它来创建使用URI的文件

我用这段代码读了这个文件:

        Uri uri = data.getData();
        ContentResolver cr = getContentResolver();
        InputStream istr =null;

        try {
            istr = cr.openInputStream(uri);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        try {
            if (resultCode == RESULT_OK) {
                Workbook wb = null;
                try {

                    wb = new HSSFWorkbook(istr);
                    istr.close();

此外,这是给我Dropbox URI的意图的代码:

      Intent fileintent = new Intent(Intent.ACTION_GET_CONTENT);
      fileintent.setType("application/vnd.ms-excel");
      try {
            startActivityForResult(fileintent, requestcode);
      } catch (ActivityNotFoundException e) {
                //lbl.setText("No activity can handle picking a file. 
                 Showing alternatives.");
      }

非常感谢!

0 个答案:

没有答案
相关问题