Assuming you are interested in a file on the web server.
You have 2 solutions here. Make your G: drive a network share or install Apache for windows and use a derivation of my code to get the csv file from the webserver.
Network share route:
You'll need a Samba client like AndSMB for your Android device. This will be used to mount the shared drive from your windows box and copy the file to your device. You'll then need to open the file like you would any other. Use this Q/A as a starting point: reading a specific file from sdcard in android
Apache route:
Install and configure Apache: http://httpd.apache.org/docs/2.2/platform/windows.html
This should be adaptable to what you want to do. Your caller would implement something like my callback. The caller instantiates the class that implements the AsyncTask. This is used to keep the network traffic off of the main GUI thread. You'll have issues on 3.0(?) and above if you don't. Slice and dice the code to your needs. I really do need to get this up as a project on github. The project is here for anyone who would need the full code: https://github.com/nedwidek/Android-Rest-API
Callback:
package com.hatterassoftware.restapi;
import java.net.URL;
import java.util.HashMap;
import android.os.AsyncTask;
import android.util.Log;
/**
* An AsyncTask implementation for performing POSTs on the Hypothetical REST APIs.
*/
public class GetTask extends AsyncTask<String, String, HttpReturn>{
private String restUrl;
private RestCallback callback;
private HashMap<String, String> headers;
private String username;
private String password;
final String TAG = "GetTask";
/**
* Creates a new instance of PostTask with the specified URL, callback, and
* request body.
*
* @param restUrl The URL for the REST API.
* @param callback The callback to be invoked when the HTTP request
* completes.
* @param requestBody The body of the POST request.
*
*/
public GetTask(String restUrl, RestCallback callback, HashMap<String, String> headers, String username, String password){
this.restUrl = restUrl;
this.callback = callback;
this.headers = headers;
this.username = username;
this.password = password;
}
@Override
protected HttpReturn doInBackground(String... params) {
try {
RestHttpUrlConnection request = new RestHttpUrlConnection(new URL(restUrl), headers, username, password);
return request.doGetRequest();
} catch (Throwable t) {
Log.e(TAG, "Exception in doInBackground", t);
return new HttpReturn(new RestException(t));
}
}
@Override
protected void onPostExecute(HttpReturn result) {
Log.d(TAG, "Entered onPostExecute");
Log.d(TAG, "result.status = " + result.status);
Log.d(TAG, "result.content = " + result.content);
callback.onTaskComplete(result);
super.onPostExecute(result);
}
}
package com.hatterassoftware.restapi;
import java.net.URL;
import java.util.HashMap;
import android.os.AsyncTask;
import android.util.Log;
/**
* An AsyncTask implementation for performing POSTs on the Hypothetical REST APIs.
*/
public class GetTask extends AsyncTask<String, String, HttpReturn>{
private String restUrl;
private RestCallback callback;
private HashMap<String, String> headers;
private String username;
private String password;
final String TAG = "GetTask";
/**
* Creates a new instance of PostTask with the specified URL, callback, and
* request body.
*
* @param restUrl The URL for the REST API.
* @param callback The callback to be invoked when the HTTP request
* completes.
* @param requestBody The body of the POST request.
*
*/
public GetTask(String restUrl, RestCallback callback, HashMap<String, String> headers, String username, String password){
this.restUrl = restUrl;
this.callback = callback;
this.headers = headers;
this.username = username;
this.password = password;
}
@Override
protected HttpReturn doInBackground(String... params) {
try {
RestHttpUrlConnection request = new RestHttpUrlConnection(new URL(restUrl), headers, username, password);
return request.doGetRequest();
} catch (Throwable t) {
Log.e(TAG, "Exception in doInBackground", t);
return new HttpReturn(new RestException(t));
}
}
@Override
protected void onPostExecute(HttpReturn result) {
Log.d(TAG, "Entered onPostExecute");
Log.d(TAG, "result.status = " + result.status);
Log.d(TAG, "result.content = " + result.content);
callback.onTaskComplete(result);
super.onPostExecute(result);
}
}
package com.hatterassoftware.restapi;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.PasswordAuthentication;
import java.net.ProtocolException;
import java.net.URL;
import java.util.HashMap;
import android.util.Base64;
import android.util.Log;
public class RestHttpUrlConnection {
private HttpURLConnection connection;
final String TAG = "RestHttpUrlConnection";
protected RestHttpUrlConnection(URL url, HashMap<String,String> headers, final String username, final String password) throws IOException {
connection = (HttpURLConnection) url.openConnection();
if(headers != null) {
for(String key: headers.keySet()) {
Log.d(TAG, "Adding header: " + key + "; " + headers.get(key));
connection.addRequestProperty(key, headers.get(key));
}
}
if(username != null) {
String auth = "Basic " + Base64.encodeToString((username + ":" + password).getBytes(), Base64.DEFAULT);
connection.addRequestProperty("Authorization", auth);
}
}
public HttpReturn doPostRequest(String postData) throws IOException {
return doPostOrPut(true, postData);
}
public HttpReturn doGetRequest() throws IOException {
return doGetOrDelete(true);
}
public HttpReturn doPutRequest(String putData) throws IOException {
return doPostOrPut(false, putData);
}
public HttpReturn doDeleteRequest() throws IOException {
return doGetOrDelete(false);
}
private HttpReturn doGetOrDelete(boolean isGet) throws ProtocolException, IOException {
if (isGet) {
connection.setRequestMethod("GET");
} else {
connection.setRequestMethod("DELETE");
}
String line;
StringBuffer output = new StringBuffer(1024);
try {
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((line = in.readLine()) != null) output.append(line);
} catch (Exception e) {
HttpReturn httpReturn = new HttpReturn(connection.getResponseCode(), output.toString());
httpReturn.restException = new RestException(e);
return httpReturn;
}
return new HttpReturn(connection.getResponseCode(), output.toString());
}
private HttpReturn doPostOrPut(boolean isPost, String data) throws ProtocolException, IOException {
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setInstanceFollowRedirects(false);
connection.setFixedLengthStreamingMode(data.getBytes().length);
if (isPost) {
connection.setRequestMethod("POST");
} else {
connection.setRequestMethod("PUT");
}
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
out.writeBytes(data);
out.flush();
out.close();
connection.connect();
String line;
StringBuffer output = new StringBuffer(1024);
try {
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((line = in.readLine()) != null) output.append(line);
} catch (Exception e) {
HttpReturn httpReturn = new HttpReturn(connection.getResponseCode(), output.toString());
httpReturn.restException = new RestException(e);
return httpReturn;
}
return new HttpReturn(connection.getResponseCode(), output.toString());
}
}