【问题标题】:how to read a text file from a dropbox link如何从保管箱链接中读取文本文件
【发布时间】:2014-10-24 19:55:58
【问题描述】:

现在我正在使用此代码将以下文本文件加载到 HashMap 但我想将 .txt 文件上传到保管箱并从保管箱链接中读取,这可能吗?

我用来在本地加载txt 文件的代码。

package com.cindra.utilities;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class PriceManager {

    private static Map<Integer, Double> itemPrices = new HashMap<Integer, Double>();

    public static void init() throws IOException {
        final BufferedReader file = new BufferedReader(new FileReader("./data/items/prices.txt"));
        try {
            while (true) {
                final String line = file.readLine();
                if (line == null) {
                    break;
                }
                if (line.startsWith("//")) {
                    continue;
                }
                final String[] valuesArray = line.split(" - ");
                itemPrices.put(Integer.valueOf(valuesArray[0]), Double.valueOf(valuesArray[1]));
            }
            Logger.log("Price Manager", "Successfully loaded "+itemPrices.size()+" item prices.");
        } catch (final IOException e) {
            e.printStackTrace();
        } finally {
            if (file != null) {
                file.close();
            }
        }
    }

    public static double getPrice(int itemId) {
        try {
            return itemPrices.get(itemId);
        } catch (final Exception e) {
            return 0;
        }
    }
}

感谢您的帮助。

【问题讨论】:

    标签: java url text hyperlink dropbox


    【解决方案1】:

    您的问题似乎有点宽泛/模糊,但如果您想以编程方式在 Dropbox 中读写文件,您应该使用 API:

    https://www.dropbox.com/developers

    例如,您可以使用Android Core SDK,它为uploadingdownloading 文件提供方法。 tutorial 是一个很好的入门方式。

    另一方面,如果您只想从已拥有或将手动创建的 Dropbox 共享链接中读取数据,请参阅此处了解如何修改它们以便直接访问:

    https://www.dropbox.com/help/201

    从那里开始,这是一个更普遍的问题,即如何从 URL 下载文件内容,而不是特定于 Dropbox。例如,this question

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-21
      • 2022-12-14
      相关资源
      最近更新 更多