【发布时间】: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