[android-developers] Re: M5 -> 0.9 Issue about file creation
Just found the problem is i didn't delete old package folder which is compiled with the M5. Everything works fine now. On 20 août, 17:00, roland <[EMAIL PROTECTED]> wrote: > In my application, i saved downloaded files from server in the package > directory which means "data/data/com.../downloadFile/file". I just > found my method didn' work anymore in 0.9 SDK. > > private void StreamToFile(String stream, String filePath){ > File file = new File(filePath); > FileOutputStream fos; > try{ > fos = new FileOutputStream(file); > DataOutputStream dos = new DataOutputStream(fos); > dos.writeBytes(stream); > Log.i("info", "file create ok "+filePath); > } > catch (FileNotFoundException e) > {e.printStackTrace();} > catch (IOException e) > {e.printStackTrace();} > > } > > I got a FileNotFoundException, it's weird this method works in M5. > > So i change it, i create the directory and file by using the mkdirs() > and createNewFile() : > private void StreamToFile(String stream, String filePath){ > String path = filePath.substring(0, filePath.lastIndexOf("/") + 1); > String fileName = filePath.substring(filePath.lastIndexOf("/") + 1); > File directory = new File(path); > if (!directory.exists()) { > Log.i("info", "mkdirs "+directory.mkdirs()); > Log.i("info", "directory "+directory.exists()); > } > File file = new File(directory, fileName); > FileOutputStream fos; > try{ > file.createNewFile(); > fos = new FileOutputStream(file); > DataOutputStream dos = new DataOutputStream(fos); > dos.writeBytes(stream); > } > catch (FileNotFoundException e) > {e.printStackTrace();} > catch (IOException e) > {e.printStackTrace();} > > } > > mkdirs() return always false, is that mean we couldn't create > directory in data? But i tried in console, it works with command line. > I'm confused, anyone has idea? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new Android 0.9 SDK beta! http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: M5 -> 0.9 Issue about file creation
Thanks! I had the same problem. On Aug 20, 8:45 am, roland <[EMAIL PROTECTED]> wrote: > Just found the problem is i didn't delete old package folder which is > compiled with the M5. Everything works fine now. > > On 20 août, 17:00, roland <[EMAIL PROTECTED]> wrote: > > > In my application, i saved downloaded files from server in the package > > directory which means "data/data/com.../downloadFile/file". I just > > found my method didn' work anymore in 0.9 SDK. > > > private void StreamToFile(String stream, String filePath){ > > File file = new File(filePath); > > FileOutputStream fos; > > try{ > > fos = new FileOutputStream(file); > > DataOutputStream dos = new DataOutputStream(fos); > > dos.writeBytes(stream); > > Log.i("info", "file create ok "+filePath); > > } > > catch (FileNotFoundException e) > > {e.printStackTrace();} > > catch (IOException e) > > {e.printStackTrace();} > > > } > > > I got a FileNotFoundException, it's weird this method works in M5. > > > So i change it, i create the directory and file by using the mkdirs() > > and createNewFile() : > > private void StreamToFile(String stream, String filePath){ > > String path = filePath.substring(0, filePath.lastIndexOf("/") + 1); > > String fileName = filePath.substring(filePath.lastIndexOf("/") + 1); > > File directory = new File(path); > > if (!directory.exists()) { > > Log.i("info", "mkdirs "+directory.mkdirs()); > > Log.i("info", "directory "+directory.exists()); > > } > > File file = new File(directory, fileName); > > FileOutputStream fos; > > try{ > > file.createNewFile(); > > fos = new FileOutputStream(file); > > DataOutputStream dos = new DataOutputStream(fos); > > dos.writeBytes(stream); > > } > > catch (FileNotFoundException e) > > {e.printStackTrace();} > > catch (IOException e) > > {e.printStackTrace();} > > > } > > > mkdirs() return always false, is that mean we couldn't create > > directory in data? But i tried in console, it works with command line. > > I'm confused, anyone has idea? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---