1

right now i'm using this code to load the following text file into a HashMap but i want to upload the .txt file to dropbox and have it read from the dropbox link, is this possible?

code i'm using to load the txt file locally.

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;
        }
    }
}

Thanks for help.

elm
  • 20,117
  • 14
  • 67
  • 113

1 Answers1

2

Your question seems a little broad/vague, but if you want to programmatically read and write files to and from Dropbox, you should use the API:

https://www.dropbox.com/developers

For example you can use the Android Core SDK which offers methods for uploading and downloading files. The tutorial is a good way to get started.

If, on the other hand, you just want to read data from a Dropbox share link you already have or will create manually, see here on how to modify them for direct access:

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

From there, it's a more general question of how to download file content from a URL, not specific to Dropbox. E.g., this question.

Community
  • 1
  • 1
Greg
  • 16,359
  • 2
  • 34
  • 44