One of several common methods of file manipulation

Source: Internet
Author: User

Online for the file operation many function tool class, no can self-surfing internet search download use, here I only provide a file moving (cut) method

/**

* Move the source files under the established folder

*/
public static void Movesrc2tag () {
//destination file
File Tagfile = new file (Localzippath);
source file
if (!tagfile.exists ())
Tagfile.mkdirs ();
File fold = new ("lijing");//files to be moved
File Fnew = new file (Localzippath + "//" + fold.getname ());
Fold.renameto (fnew);

}


There are a lot of ways to cut the first copy to the specified path, and then delete the files that need to be moved, but this is a bit verbose, this method is relatively simple.

Here are some of the ways I can use multiple files in my project.

/**
* Move the annotation file to the selected path
*/
private void Movesrc2tag () {
try {
Target file
File Tagfile = new file (Localzippath);
Source file multiple
for (int i = 0; i < imgpaths.size (); i++) {
String childsrc = Imgpaths.get (i). Get ("Imgpath"). ToString ();
File fold = new file (childsrc);//files to be moved
if (!tagfile.exists ())
Tagfile.mkdirs ();
File Fnew = new file (Localzippath + "//" + fold.getname ());
Fold.renameto (fnew);
Toast.maketext (
Mainactivity,
Mainactivity.getresources (). GetString (
r.string.dataexport_comment_success),
Toast.length_short). Show ();
}
} catch (Exception e) {
Toast.maketext (
Mainactivity,
Mainactivity.getresources (). GetString (
R.string.dataexport_comment_faild)
+ e.tostring (), Toast.length_short). Show ();
}
}


To explain briefly, I put the full path of the file that needs to be moved in a list.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

One of several common methods of file manipulation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.