android系统中导入和导出CSV文件 [英] Import and export CSV file in android

查看:157
本文介绍了android系统中导入和导出CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我希望能够从CSV文件导出/导入。

I have an app where I want to be able to export to/import from CSV Files.

在用例我希望将数据导出到一个CSV文件,将手机连接到PC并编辑CSV那里,重新导入文件之后回到应用程序。

In a Use-Case I want to export data into a CSV File, connect the phone to a PC and edit the CSV there and re-import the file afterwards back into the app.

我目前使用的是摩托罗拉剃刀我(最新的Andr​​oid版)和不管在哪里我试图保存文件时,它不会出现在手机连接到计算机(没有的话)

I am currently using a Motorola Razor I (latest android version) and no matter where I try to save the file, it does not appear to be public when connecting the phone to a computer (it's not there)

我可以看到在Android文件浏览器本身的文件,所以它的存在,但在Windows资源管理器的文件不存在。

I can see the file on the android File Browser itself, so it is there, but in Windows Explorer the file is not there.

什么是实现这样的功能以适当方式:

What would be a proper way to implement such a feature:


  • 导出为CSV

  • 在电脑编辑

  • 重新导入相同的文件

我使用功能 getExternalDirectory(),也试过 getExternalDirectoryPublic() - 在任何情况下,文件不会出现在计算机上。

I've used function getExternalDirectory() and have also tried getExternalDirectoryPublic() - in either cases the file doesn't appear on the computer.

任何提示高度AP preciated!

Any hints highly appreciated!

推荐答案

好吧,看来,我错过了,为了使文件出现在电脑上的东西。事情是,Android的对待这些文件不是直接的,而是MediaScanner不 - !所以我不得不做的是告诉MediaScanner有关新的文件和它的作品

Ok, it seems, I missed something in order to make the file appear on the computer. Thing is, android treats the files not directly, but the MediaScanner does - so all I had to do is tell the MediaScanner about the new File and it works!

getExternalStoragePublicDirectory写入文件()和之后的文件保存通话

Writing the File with getExternalStoragePublicDirectory() and after the file is saved call

MediaScannerConnection.scanFile(MainActivity.this, new String[] { filename }, null, null);

要告诉MediaScanner有关新文件

to tell the MediaScanner about the newly file

希望任何人发现它有用

这篇关于android系统中导入和导出CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆