javaÖÐÉÏ´«Í¼Æ¬
1. ActionFormÖÐÌí¼ÓÊôÐÔ£¬FormFileÀàÐͶÔÏó¡£
private FormFile upLoadFile;
public FormFile getUpLoadFile() {
return upLoadFile;
}
public void setUpLoadFile(FormFile upLoadFile) {
this.upLoadFile = upLoadFile;
}
2. Action ÖÐÔö¼ÓÐ޸ķ½·¨¡£
public ActionForward save(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
PayDirMenuForm myForm = (PayDirMenuForm) form;
PayDirMenu myObj = new PayDirMenu();
BeanUtils.copyProperties(myObj, myForm);
PayDirMenuManager mgr = (PayDirMenuManager)
getBean("PayDirMenuManager");
// »ñµÃÎļþ
FormFile file = myForm.getUpLoadFile();//formÖÐÔö¼ÓµÄÊôÐÔ
// »ñµÃTomcateµÄ·¾¶
String objpath = request.getRealPath("plan");
// »ñµÃÉÏ´«µÄÎļþµÄÃû×Ö
String fileName = file.getFileName();//»ñÈ¡ÉÏ´«Í¼Æ¬µÄÎļþÃû
// ½ØÈ¡×Ö·û´®£¬»ñµÃºó׺Ãû
StringsuffixFileName =
fileName.substring(fileName.lastIndexOf("."));
//ÅжÏÉÏ´«ÎļþµÄÀàÐÍ
if(!".txt".equals(suffixFileName)&&!".doc".equals(suffixFileName)&&!".xls".equals(suffixFileName)&&!".jpg".equals(suffixFileName)&&!".gif".equals(suffixFileName)&&!".ppt".equals(suffixFileName))
{
request.getSession().setAttribute("msg1", "<font
color='red'>ÉÏ´«µÄÎļþ¸ñʽ²»ÕýÈ·£¡</font>");
return null;
}
// »ñµÃÄÚÈÝ
byte[] fileData = file.getFileData();
if (myObj.getMenuOid() != null && myObj.getMenuOid().intValue() ==
0){ //Ôö¼Ó
//дÈëµ½Á÷ÖÐ
FileOutputStream out = new FileOutputStream(new File(objpath + "\\"
+ fileName));
String filePath = objpath + "\\"+ fileName;
out.write(fileData);
out.close();
out.flush();
//дÈëÊý¾Ý¿â
myObj.setMenuImage(filePath);
mgr.saveObj(myObj);
}
else
Ïà¹ØÎĵµ£º
JavaÅäÖÃÎļþ¶ÁÈ¡Óи÷ÖÖ²»Í¬µÄÎļþ£¬µ«ÊÇÓÉÓÚ´ò°üJarºóµÄ·¾¶¸Ä±ä£¬ÍùÍùÔÚÏîÄ¿ÖÐÄÜÕýÈ·¶ÁÈ¡µÄÅäÖÃÎļþÔÚJarºó±ä³ÉÎļþ²»´æÔڵı¾ß£¬ÏÂÔÚÌá³ö¼¸¸÷²»Í¬µÄÅäÖÃÎļþ¶ÁÈ¡·½Ê½£¬½ö¹©²Î¿¼
Ò»¡¢Ö±½ÓÎļþ¶ÁÈ¡
File f = new File("you config file path");
FileReader fr = new FileReader(f);
BufferReader br = new ......
java¿ª·¢µÄ³ÌÐòµÄ±£»¤
ÖÚËùÖÜÖª£¬javaΪ¿ª·¢ÓïÑÔÌṩÁ˺ܷ½±ãµÄ¿ª·¢Æ½Ì¨£¬µ«¿ª·¢³öÀ´µÄ³ÌÐòºÜÈÝÒ×ÔÚ²»Í¬µÄƽ̨ÉÏÃæ±»ÒÆÖ²£¬ÏÖÔÚÔ½À´Ô½¶àµÄÈËʹÓÃËü¿ª·¢Èí¼þ¡£
JavaÓÐËü·½±ãµÄÒ»¸ö·½Ã棬µ«ËüͬʱҲ´ø¸øÁË¿ª·¢ÕßÒ»¸ö·³ÄÕ£¬Õâ¾ÍÊDZ£»¤µÄ°ì·¨²»¶à£¬¶øÇÒ´ó¶àÊý²»ÊǺܺ ......
²Î¿¼´úÂë:
class SuperClass {
private int n;
SuperClass() {
System.out.println("SuperClass()");
}
SuperClass(int n) {
System.out.println("SuperClass(" + n + ")");
this.n = n;
}
}
class SubClass extends SuperClass {
private int n ......
try {
Runtime.getRuntime().exec("C:\\xxx.exe");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} ......