Доброго времени суток. У меня такая проблема, есть метод, который стягивает файл с дропбокса, по прямой публичной ссылке. Но при его вызове, программа вылетает, известно что метод начинает роботу, така как папка создается. Вот код метода
// Download dictionary to SD card
protected static void downloadDictionary () throws IOException {
// Check that SD card is mounted
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
return;
}
// Making directory for dictionary
String downDir = Environment.getExternalStorageDirectory() + "/" + DIR;
File donwFile = new File(downDir);
donwFile.mkdir();
// Downloading dictionary
try {
URL url = new URL(FILEURL);
HttpURLConnection urlConnect = (HttpURLConnection) url.openConnection();
urlConnect.setRequestMethod("GET");
urlConnect.setDoOutput(true);
urlConnect.connect();
FileOutputStream fStream = new FileOutputStream(new File(donwFile, DICTIONARY));
InputStream inputStream = urlConnect.getInputStream();
byte[] buffer = new byte[1024];
int lenght = 0;
while ((lenght = inputStream.read(buffer)) > 0) {
fStream.write(buffer, 0, lenght);
}
fStream.close(); // Close write stream
} catch (MalformedURLException e) {
// MalformedURLException
}
}
Вызов происходит в onCreate
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if (!DictionaryLoader.getSdFile().exists()){
// Downloading dictionary in background
try {
DictionaryLoader.downloadDictionary();
} catch (IOException e) {
// IOExeption
}
Но при запуске, вместо того что бы скачать файл, программа просто вылетает с ошибкой.