[英]How do I access a text file from GCP Storage and parse it?
I have an app I want to make for Android. 我有一个要制作用于Android的应用程序。 I have decided to store the information I will display in a text file and parse it, rather than a database since the data is so simple. 我决定将要显示的信息存储在一个文本文件中并进行解析,而不是数据库,因为数据是如此简单。
The info is just two lines of text, a word and a short description of that word. 信息仅是两行文字,一个单词和对该单词的简短描述。 I want the app to get each pair (word, description) from the text file and display it on a card in the app. 我希望应用程序从文本文件中获取每一对(单词,描述),并将其显示在应用程序中的卡上。
I stored the .txt file in Google Cloud Platform Storage and now I need help writing the code to access the file(s) and parse them to use in a Cards UI. 我将.txt文件存储在Google Cloud Platform Storage中,现在我需要帮助编写代码来访问文件并解析它们以在Cards UI中使用。
I can find no helpful examples of how to get this file then parse it in the app in a smooth way. 我找不到任何有用的示例,说明如何获取此文件,然后在应用中以流畅的方式对其进行解析。
You can use a client library to open the file and read it. 您可以使用客户端库打开文件并读取它。 For example, the Python client library is at https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/functions 例如,Python客户端库位于https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/functions
and your code would look like this: 您的代码将如下所示:
import cloudstorage
try:
gcs_file = cloudstorage.open(filename, 'r', content_type='text/plain')
# process as normal ...
except cloudstorage.NotFoundError:
pass
Sample Java client code is at https://cloud.google.com/storage/docs/xml-api-java-samples 示例Java客户端代码位于https://cloud.google.com/storage/docs/xml-api-java-samples
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.