简体   繁体   English

如何从GCP存储访问文本文件并进行解析?

[英]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.

相关问题 如何从测试项目访问内部存储? - How do I access the internal storage from a test project? 如何从WebView引用存储在内部存储中的文件? - How do I reference a file stored in internal storage from a WebView? Android内部存储,如何正确解析JSON文本文件 - Android Internal Storage, how to properly parse a JSON text file 如何在Android中访问JUnit测试的文本文件? - How do I access a text file for JUnit test in Android? 如何从Google Assistant获取文本,以便我可以解析文本以执行某些操作? - How can I get text from Google Assistant so that I can parse the text to do certain action? 如何在Android应用上从外部存储解析或读取json文件 - How to parse or read json file from external storage on Android app 如何访问/读取/写入Android设备上内部存储中的Documents文件夹? - How do I access/read from/write to Documents folder in Internal Storage on Android devices? 我在资产文件夹中有一个文本文件。 如何从该文本文件访问随机句子? - I have a text file in the assets folder. How can I access a random sentence from that text file? 如何访问android.os.storage.IMountService? - How do I access android.os.storage.IMountService? (读取并)从内部存储解析XML文件 - (Read and) Parse an XML file from Internal Storage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM