See what's wrong with the following code:
public static String writefiletoremote (file file) throws Exception {Postmethod filepost = new Postmethod (Common.getinstan CE (). GetProperty ("project/remotefileserver") + "/attach?action=upload"); try {part[] parts = new Part[4];p arts[0] = new Stringpart ("File_kind", "2");p arts[1] = new Stringpart ("RECORD", "true");p arts[2] = new Stringpart ("File_kind", "2"); PARTS[3] = new Filepart ("File_path", File.getname (), FILE), filepost.setrequestentity (New Multipartrequestentity ( Parts,filepost.getparams ())); HttpClient client = new HttpClient () or//Because the file to be uploaded may be larger, so the maximum connection timeout is set Client.gethttpconnectionmanager (). Getparams (). setconnectiontimeout, int status = Client.executemethod (FilePost); String file_path = "", if (status = = HTTPSTATUS.SC_OK) {//gets fileidstring res = filepost.getresponsebodyasstring from the server response string ( ); String retfilestr = "Retobj.fileid = \" "; res = res.substring (Res.indexof (RETFILESTR) + retfilestr.length ()); File_path = Res.substring (0, Res.indexof (' "')). Replace (' | ', '/');} File.delete (); return File_path;} catch (Exception e) {e.printstacktrace (); throw new Exception ("an exception occurred while writing the remote file! ");}}
Error:
Caused by:java.lang.Exception: An exception occurred while writing remote files! Com.age.sale.view.tool.ImportTool.writeFileToRemote (importtool.java:112)
There is no way to locate the error at this time!
Therefore, try catch should be removed, if you want to catch, you must record the error message! And show to the front desk! Because querying the log is a very troublesome thing.
This article originates from: Ouyida3 's CSDN Blog
2015.3.5
Use Java's try catch with caution