0

could you help me about this?.When the users opens the app or install the app the process is to automatically move files in a certain folder. Guys, any suggestion, codes or links are helpful and appreciated ... :D

Thanks in advance.

p0p0ts
  • 5
  • 2
  • 6
  • I have tried set's of codes and test this [link]http://stackoverflow.com/questions/4178168/how-to-programmatically-move-copy-and-delete-files-and-directories-on-sd but i do not know where to implement this...thanks for the response sir!!!:D – p0p0ts Jun 30 '13 at 14:25
  • Use preference. Let say, set a preference key named as "isRunningFirst", which will be true by default. During app start you checked the key. If true, move your files to the desired directory using standard JAVA I/O API. – Bharat Jyoti Jun 30 '13 at 17:32
  • @Bharat Jyoti thank you sir for the response.. could you teach me how to move files?. I have tried those codes in the internet that tackles moving of files but I wasn't able to move anything...could you show me an example of how to move files ? – p0p0ts Jul 01 '13 at 15:21
  • 1
    Hi, Java.io.File does not contains any ready make move file method, but you can workaround with the following two alternatives : File.renameTo(). Copy to new file and delete the original file. Visit this link http://www.mkyong.com/java/how-to-move-file-to-another-directory-in-java/ – Bharat Jyoti Jul 01 '13 at 16:02
  • @Bharat Jyoti thank you sir, I really appreciate the help. I will visit the link try it...thanks again... – p0p0ts Jul 01 '13 at 16:06

1 Answers1

0

For move file you can use below code:

File from = new File(Environment.getExternalStorage().getAbsolutePath()+"/folder1/file.ext");
File to = new File(Environment.getExternalStorage().getAbsolutePath()+"/folder2/file.ext");
from.renameTo(to);

just use this method for folders that be on same mount point.

SadeghAlavizadeh
  • 609
  • 3
  • 17
  • 33