About multiple threads manipulating a file file handle (file stream in Java)

Source: Internet
Author: User

Approving basic information
public static map<string, string> writebasictomap (Class gcprojcheckupclas,string filedirpath,map<string, Object> map) throws exception{
Document doc = Documenthelper.createdocument ();
Add root node
Element root = Doc.addelement ("Gcdata");
Get class Name
String classname= Strutils.getclassnamebypackage (Gcprojcheckupclas.getname ());
Add child elements
Element gcprojcheckup = root.addelement (className);//lowercase is not required

Add nodes.
Field [] Gcprojcheckupfields = Gcprojcheckupclas.getdeclaredfields ();
for (int i = 0; i < gcprojcheckupfields.length; i++) {
System.out.println (Gcprojcheckupfields[i].getname ());
String key = Gcprojcheckupfields[i].getname ();
Element element = Gcprojcheckup.addelement (key);//tag and attribute naming consistent
Element.settext (Map.get (Key.tolowercase ()) ==null? "": (String) Map.get (Key.tolowercase ()));

}
Special treatment Leadergxunicode_organofleader
Element element = Root.addelement ("Leadergxunicode_organofleader");
Element.addtext (Map.get ("Lgol") ==null? "":(String) map.get ("Lgol"));


Instantiating an output Format object
OutputFormat format = Outputformat.createprettyprint ();
Set Output encoding
Format.setencoding ("UTF-8");
Create a file object to write to
String fileName = Nameutils.getfilename (Map.get ("Unitid") ==null? ": Map.get (" Unitid "). ToString (), Map.get (" Unitname ") ==null?": Map.get ("Unitname"). ToString (), Strutils.getclassnamebypackage (Gcprojcheckupclas.getname ()));
String Finalpath=commonpath.inrootpath+filedirpath + file.separator+ filename+ ". xml";
System.out.println (Finalpath);
File File = new file (Finalpath);
Generate XmlWriter objects, parameters in constructors are file streams and formats that require output
FileOutputStream FileOutputStream = new FileOutputStream (file);
XMLWriter writer = new XMLWriter (fileoutputstream, format);
Start writing, the Write method contains the Document object created above
Writer.write (DOC);
if (writer!=null) writer.close ();
if (fileoutputstream!=null) fileoutputstream.close ();

map<string, string> backmap = new hashmap<string, string> ();
Backmap.put ("filename", filename);
FileInputStream InputStream = new FileInputStream (Finalpath);
String MD5 = Digestutils.md5hex (InputStream);
if (inputstream!=null) {inputstream.close ();};
Backmap.put ("MD5", MD5);
return backmap;
}

About multiple threads manipulating a file file handle (file stream in Java)

Related Article

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.