私のプロジェクトでDropboxを使用して、dropboxから小さなURLを取得しています。これはhttp://www.db.tt/xyzabcのようです。HTTP接続からHTTPS接続にリダイレクトするファイルをダウンロードする
HTC My touch
でファイルをダウンロードしようとすると、私のコードは正常に動作しますが、試してみるとMotorola Atrix
はexception unknown host db.tt
を投げます。
実際に最初に私はhttp://www.db.tt/xyzabc
のようなURLを持っています。これは、私がexception
を得るよりもオープンしています。例外として、ファイルを含む実際のURLを取得し、例外的にHTTPS URLです。私はここに、ファイルのダウンロードを開始することは私のために働く私のコードです:
public static void fileUrl(String fAddress, String localFileName,
String destinationDir) {
OutputStream outStream = null;
URLConnection uCon = null;
InputStream is = null;
try {
URL url;
byte[] buf;
int ByteRead, ByteWritten = 0;
url = new URL(fAddress);
outStream = new BufferedOutputStream(new FileOutputStream(
destinationDir + localFileName));
try {
// Here i have "http://www.db.tt/xyzabc"
// after i hit url i get exception and in exception that
// FileNotFoundException at https://www.dropbox.com/abcxyz
// i get actual actual url i parse that exception and
//retrive https://www.dropbox.com/xyzabc(actual url)
// but in motorolla atrix instead of that url i get
// unknownhost exception "db.tt"
uCon = url.openConnection();
// uCon.connect();
is = uCon.getInputStream();
} catch (Exception e) {
url = new URL(e.getMessage().substring(
e.getMessage().indexOf("https"),
e.getMessage().length()));
outStream = new BufferedOutputStream(new FileOutputStream(
destinationDir + localFileName));
uCon = url.openConnection();
is = uCon.getInputStream();
}
buf = new byte[size];
while ((ByteRead = is.read(buf)) != -1) {
outStream.write(buf, 0, ByteRead);
ByteWritten += ByteRead;
}
System.out.println("Downloaded Successfully.");
System.out.println("File name:\"" + localFileName
+ "\"\nNo ofbytes :" + ByteWritten);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
is.close();
outStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
私はしばらくこの問題を残しました。最終的に、いくつかの短いハイパーリンク[Dropbox audio in my case]が実際にhtml DOWNLOAD画面にリダイレクトされるように見えます。 これは、リンクがIMHOを行うべきでは役に立たない。 – loser114491