Android下载文件到SDCard缺少文本格式

时间:2014-03-25 09:01:13

标签: android file

我使用此代码将文件从Internet下载到SDCard

try {
    File root = android.os.Environment.getExternalStorageDirectory();

    File dir = new File (root.getAbsolutePath() + "/Data");

    if(dir.exists()==false) {
        dir.mkdirs();
    }

    URL url = new URL(DownloadUrl);
    File file = new File(dir, fileName);

    URLConnection ucon = url.openConnection();

    InputStream is = ucon.getInputStream();
    BufferedInputStream bis = new BufferedInputStream(is);

    ByteArrayBuffer baf = new ByteArrayBuffer(5000);

    int current = 0;
    while ((current = bis.read()) != -1) {
        baf.append((byte) current);
    }

    FileOutputStream fos = new FileOutputStream(file);

    fos.write(baf.toByteArray());

    fos.flush();

    fos.close();

} catch (IOException e) {

    Log.d("DownloadManager", "Error: " + e);
}

但下载后的文件全部删除了' \ n' (新行),任何人都帮我如何下载文件,但保持' \ n'字符? 非常感谢你!

0 个答案:

没有答案