如何在 Android 上仅下载 .csv 文件的第一部分?

发布于 2024-10-01 05:22:11 字数 183 浏览 3 评论 0原文

在我的应用程序中,我必须提供可从网络访问的 .csv 文件中的一些数字。现在,这个 .csv 相当大了。我不想下载并处理整个内容,没有意义。我的数字总是在文件的开头,在明确指定的位置 - 比如说位置 5 到 10。

您能给我一些关于如何实现这一点的提示吗?我知道如何下载整个内容,但不知道如何仅下载其中的一部分。

谢谢。

In my app, I have to present a few numbers from a .csv file that's accessible from the web. Now, this .csv is quite big. I don't want to download and process the whole thing, there's no point. My numbers are always in the beginning of the file, in well specified positions - lets say position 5 to 10.

Could you give me some tips on how to implement this? I know how to download the whole thing, but don't know how to download only a part of it.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

巴黎盛开的樱花 2024-10-08 05:22:11

Psuedo:

BufferedReader br = new BufferedReader (new InputStreamReader(remoteStream));
String sFirstLine = br.readLine();

remoteStream 是连接到远程服务器的流。获取流的句柄与实际下载不同。只有 BufferedReader.readLine() 实际上下载任何内容

Psuedo:

BufferedReader br = new BufferedReader (new InputStreamReader(remoteStream));
String sFirstLine = br.readLine();

remoteStream is the stream of the connection to the remote server. Getting a handle to the stream is not the same as actually downloading. Only the BufferedReader.readLine() actually downloads anything

已下线请稍等 2024-10-08 05:22:11

您有权访问该文件所在的服务器吗?您可以在服务器上进行处理。

例如,如果文件位于 /myfile.csv,您可以在服务器上打开 mycsvfile.php 的流,该流会进行处理并返回您感兴趣的位置。当然,您还必须编写PHP 代码(或其他)来执行此操作。

Do you have access to the server the file is on? You could do your processing on the server.

For example, if the file is at /myfile.csv, you could open a stream to mycsvfile.php on the server, which does the processing and returns the positions you're interested in. Of course you'd also have to write the PHP code (or whatever) to do this.

话少情深 2024-10-08 05:22:11

您没有说明文件是在什么协议下提供的,但假设像 http 或 ftp 这样的标准,应该没有什么可以阻止您开始下载,然后在获得所需的文件数量后中止下载,前提是您自己实现协议的 android 端,而不是使用内置机制之一(除非您发现内置机制也使您能够中止)。

我不认为在java或ndk中实现一个简单的http下载器太复杂。在 android 上执行此操作不应该是唯一的挑战,因为您可以随时使用所有正常的 java 和底层 Linux 网络套接字机制。

You don't say what protocol the file is served under, but assuming something standard like an http or ftp there should be nothing to stop you from starting the download and then aborting it once you've gotten as much of the file as you need, provided that you implement the android end of the protocol yourself rather than using one of the built in mechanisms (unless you find the built in mechanism also gives you the ability to abort).

I don't believe the implementation of a simple http downloader in java or ndk to be too complicated. Doing it on android should not be uniquely challenging as you have all of the normal java and underlying linux network sockets mechanisms readily available.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文