確定爲您的意見和最新的修改,可以說你的文本文件的URL是這樣的
http://www.example.com/myTextFile.txt
你可以做什麼像這
StringBuffer myString = new StringBuffer("");
try {
// Create a URL
URL url = new URL("http://www.example.com/myTextFile.txt");
// Read the text
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String string;
while ((string = in.readLine()) != null) {
// string is one line of text; readLine() reads the newline
myString.append("__"+string);
}
in.close();
}
catch (Exception e) {
}
return myString;
這裏是你的doInBackground()方法的示例r AsyncTask
類您將分割字符串並將它們插入到sqlite中
@Override
protected String doInBackground(String... params) {
String myString = params[0];
String[] splitedString = myString.split("__");
ContentValues cv=new ContentValues();
cv.put("firstline", splitedString[0]); //where firstline is your column name
cv.put("secondline", splitedString[1]);
db.insert(yourTable, null, cv); //where db is your instance of writable database
db.close(); //Close the connection
}
您的數據採用哪種格式?這是一個JSON格式的數據在鏈接或其他東西,請在這個問題明確。 –
@ShreeKrishna我在編輯中添加了格式。一個字符描繪了每一條信息串。瓦片名稱的本地路徑與文件位於同一臺服務器上,並位於同一位置。 –
這裏有一個廣泛的問題。 1)文件的網絡請求2)解析文件3)將分析的信息存儲在sqlite數據庫中。我建議你將你的研究分解成這些單獨的部分 –