public void downloadFileViaHTTP()
{
Log.d("downloadFileViaHttp", "downloadFileViaHTTP...");
try
{
String urlFile = "http://finance.yahoo.com/d/quotes.csv?s=ACC.NS+AMBUJACEM.NS+ASIANPAIN.NS+AXISBANK.NS+BAJAJ-AUT.NS+BANKBAROD.NS+" + "BHARTIART.NS+BHEL.NS+BPCL.NS+CAIRN.NS+CIPLA.NS+COALINDIA.NS+DLF.NS+DRREDDY.NS+GAIL.NS+GRASIM.NS+HCLTECH.NS+HDFC.NS+HDFCBANK.NS+ HEROHONDA.NS+HINDALCO.NS+HINDUNILV.NS + +"HEROHONDA.NS+HINDALCO.NS+HINDUNILV.NS+ICICIBANK.NS+IDFC.NS+ITC.NS+INFY.NS+JINDALSTE.NS+JPASSOCIA.NS+KOTAKBANK.NS+LT.NS+LUPIN.NS+M%26M.NS+"+ "MARUTI.NS+NTPC.NS + ONGC.NS+PNB.NS+POWERGRID.NS+RANBAXY.NS+RELIANCE.NS+RELINFRA.NS+SBIN.NS+SESAGOA.NS+SIEMENS.NS+SPARC.NS+TATAMOTOR.NS+"+"TATAPOWER.NS+TATASTEEL.NS+TCS.NS+ULTRACEMC.NS+WIPRO.NS+ %5ENSEI&f=snl1hgp";
URL url = new URL(urlFile);
Log.d("url", url.toString());
BufferedReader reader=null;
Log.d("1","1");
// create the new connection
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
Log.d("downloadFileViaHttp:HttpURLconnection", " " + urlConnection);
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
//and connect!
Log.d("2","2");
urlConnection.connect();
// pointer to the downloaded file path
File sdcard= Environment.getExternalStorageDirectory();
File MyFilePtrDest=new File(sdcard,"quotes.csv");
Log.d("downloadFileViaHttp","localFileName = " + MyFilePtrDest.toString());
// this will be used in reading the data from the Internet
InputStream inputStream = urlConnection.getInputStream();
// this will be used to write the downloaded data into the file we
// created
FileOutputStream fileOutput = new FileOutputStream(MyFilePtrDest);
byte[] buffer = new byte[1024];
int bufferLength = 0; // used to store a temporary size of the buffer
// write buffer contents to file
while ((bufferLength = inputStream.read(buffer))>0)
{
Log.d("content","content "+inputStream.read(buffer, 0, bufferLength));
// add the data in the buffer to the file in the file output
// stream (the file on the sd card
fileOutput.write(buffer, 0, bufferLength);
}
inputStream.close();
// close the output stream when done
// fileOutput.flush();
// fileOutput.close();
urlConnection.disconnect();
}
catch (IOException e)
{
// data were not found
dataNotFound = true;``
e.printStackTrace();
}
}
urlconnection.connect()
ポインターが上記のコードのステートメントに到達するたびに、yahoo ファイナンスから csv ファイルをダウンロードしようとしていjava.net.unknownHostException
ます。上記のコードの問題をどのように解決できますか?
以下は丸太の猫です
03-29 19:10:09.770: W/System.err(32292): java.net.UnknownHostException: finance.yahoo.com 03-29 19:10:09.770: W/System.err(32292): Java で。 net.InetAddress.lookupHostByName(InetAddress.java:506) 03-29 19:10:09.770: W/System.err(32292): java.net.InetAddress.getAllByNameImpl(InetAddress.java:294) 03-29 19: 10:09.770: W/System.err(32292): java.net.InetAddress.getAllByName(InetAddress.java:256) 03-29 19:10:09.770: W/System.err(32292): org.apache で.harmony.luni.internal.net.www.protocol.http.HttpConnection.(HttpConnection.java:69) 03-29 19:10:09.770: W/System.err(32292): org.apache.harmony.luni で.internal.net.www.protocol.http.HttpConnection.(HttpConnection.java:48) 03-29 19:10:09.770: W/System.err(32292): org.apache.harmony.luni.internal.net で.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322) 03-29 19:10:09.770: W/System.err(32292): org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89 で) 03-29 19:10:09.770: W/System.err(32292): org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285) で 03- 29 19:10:09.770: W/System.err(32292): org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267) で 03-29 19: 10:09.770: W/System.err(32292): org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205) 03-29 19:10:09.770 で: W/System.err(32292): com.indusa.stockapp.stockListing.StockListing.downloadFileViaHTTP(StockListing.java:252) 03-29 19:10:09.770: W/System.err(32292):com.indusa.stockapp.stockListing.StockListing.onCreate(StockListing.java:99) 03-29 19:10:09.770: W/System.err(32292): android.app.Instrumentation.callActivityOnCreate(Instrumentation.java: 1050) 03-29 19:10:09.770: W/System.err(32292): android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623) 03-29 19:10:09.770: W/System.err( 32292): android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675) 03-29 19:10:09.770: W/System.err(32292): android.app.ActivityThread.access$1500(ActivityThread.java: 121) 03-29 19:10:09.770: W/System.err(32292): android.app.ActivityThread$H.handleMessage(ActivityThread.java:943) 03-29 19:10:09.770: W/システム。 err(32292): android.os.Handler.dispatchMessage(Handler.java:99) 03-29 19:10:09.780: W/System.err(32292): android.os.Looper で。ループ (Looper.java:130) 03-29 19:10:09.780: W/System.err(32292): android.app.ActivityThread.main(ActivityThread.java:3770) 03-29 19:10:09.780: W/System.err(32292): java.lang.reflect.Method.invokeNative(ネイティブ メソッド) 03-29 19:10:09.780: W/System.err(32292): java.lang.reflect.Method で。 (Method.java:507) 03-29 19:10:09.780: W/System.err(32292): com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912) 03-29 で19:10:09.780: W/System.err(32292): com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670) 03-29 19:10:09.780: W/System.err(32292 ): dalvik.system.NativeStart.main(ネイティブ メソッド) でReflect.Method.invokeNative(ネイティブ メソッド) 03-29 19:10:09.780: W/System.err(32292): java.lang.reflect.Method.invoke(Method.java:507) 03-29 19:10 で:09.780: W/System.err(32292): com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912) 03-29 19:10:09.780: W/System.err(32292) : com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670) 03-29 19:10:09.780: W/System.err(32292): dalvik.system.NativeStart.main(ネイティブ メソッド) でReflect.Method.invokeNative(ネイティブ メソッド) 03-29 19:10:09.780: W/System.err(32292): java.lang.reflect.Method.invoke(Method.java:507) 03-29 19:10 で:09.780: W/System.err(32292): com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912) 03-29 19:10:09.780: W/System.err(32292) : com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670) 03-29 19:10:09.780: W/System.err(32292): dalvik.system.NativeStart.main(ネイティブ メソッド) で670) 03-29 19:10:09.780: W/System.err (32292): dalvik.system.NativeStart.main (ネイティブ メソッド) で670) 03-29 19:10:09.780: W/System.err (32292): dalvik.system.NativeStart.main (ネイティブ メソッド) で