[英]Linking and copying an external (Removable storage) file in android
I have an open question I would like to ask before starting development of functionality, only to learn more about the subject afterwards, just to start all over again ;) I tried searching, but am not really sure what to search for. 在开始开发功能之前,我有一个开放的问题要问,只是以后要学习更多有关该主题的知识,只是从头开始;)我尝试搜索,但不确定要搜索什么。 Therefor, I would like to pick your brains a bit here...
为此,我想在这里稍加注意...
Here is the current situation: I have an app that stores activity/event logs. 当前情况如下:我有一个存储活动/事件日志的应用程序。 In a simplified example: "Person A filled a glass with 100ml of water"
在一个简化的示例中:“人员A用100毫升水填充了玻璃杯”
This is stored as a record in a single table. 这作为记录存储在单个表中。
Now, for the requirement of the new functionality: I connect an external storage device via USB to my tablet. 现在,对于新功能的要求:我通过USB将外部存储设备连接到平板电脑。 On this storage device there are several text files.
在此存储设备上,有几个文本文件。 Each file contains parameters of an activity/event, similar to the one described above, but with different data.
每个文件都包含活动/事件的参数,与上述参数类似,但数据不同。
I would like to create a function to import these files, read some of their content into the database as new records, and then store the file somewhere on the tablet, with a link to the file as a field in the DB. 我想创建一个函数来导入这些文件,将它们的某些内容作为新记录读入数据库,然后将该文件存储在平板电脑上的某个位置,并带有指向该文件的链接作为DB中的字段。 Ideally I would have liked to store the contents of the entire text file in a field, or a field in a related 1:1 table, but these files could be as big as 1MB (1MB would be very rare, but possible. Avg is around 100KB).
理想情况下,我希望将整个文本文件的内容存储在一个字段中,或者存储在相关的1:1表中的一个字段中,但是这些文件可能大到1MB(1MB很少,但是可能。大约100KB)。
So, my questions are: 因此,我的问题是:
Thanks in advance, all replies are much appreciated! 在此先感谢您,感谢所有回复!
No one wants to take the chance? 没有人想借此机会吗? :)
:)
For future readers with the same problem: It is possible to read a file from a usb connected device. 对于将来遇到相同问题的读者:可以从USB连接的设备读取文件。 Keep in mind that reading the file directly from the file system is different than reading it as an attachment in a mail for instance.
请记住,直接从文件系统读取文件不同于将其作为邮件附件读取。 Not much more than a different path though ;)
只是一条不同的路径而已;)
I ended up reading the file into a DB, splitting the lines across a record. 我最终将文件读取到数据库中,将行拆分成一条记录。 In other words, not adding the whole file (or even a complete line) in a field, but rather parsing the file into a single record, split up into various fields.
换句话说,不是在字段中添加整个文件(甚至是整行),而是将文件解析为单个记录,然后分成多个字段。
Two things I came across that might help you. 我遇到的两件事可能会对您有所帮助。 Reading a file is pretty fast, but do not make the mistake I made by writing these lines to the database one by one.
读取文件的速度非常快,但不要犯我逐行将这些行写入数据库所犯的错误。 Better to add them all to a transaction, and commit at once.
最好将它们全部添加到事务中,然后立即提交。 The other, you can use a read buffer to read the file, instead of the default inputstream.
另外,您可以使用读取缓冲区来读取文件,而不是默认的输入流。 This also speeds up reading of large files.
这也可以加快大型文件的读取速度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.