按时间自动生成文件句,高手请帮忙。 请问在STRUTS框架下开发时,文件上传时,按时间自动生成文件名,该 如何写呢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 目标文件名=Long.toString(new java.util.Date().getTime())+"."+扩展文件名;重复了吧 //上传目录 GregorianCalendar c = new GregorianCalendar () ; int year = c.get (Calendar.YEAR) ; sUploadLocalDir = "\\download\\" + year + "\\" ; java.io.File myDir = new java.io.File (request.getRealPath ( sUploadLocalDir)) ; if (!myDir.exists ()) { myDir.mkdir () ; } sFileName = myFile.getFileName () ; //处理文件名 if (sFileName != null && !sFileName.equals ("")) { String prefix = "" ; String postfix = "" ; int num = 0 ; num = sFileName.lastIndexOf (".") ; postfix = sFileName.substring (num + 1) ; long now = System.currentTimeMillis () ; prefix = String.valueOf (now) ; newFileName = prefix + "." + postfix ; String filePath1 = request.getRealPath (sUploadLocalDir + newFileName) ; myFile.saveAs (filePath1, mySmartUpload.SAVE_PHYSICAL) ; } //文件的上传处理完成 long n = System.currentTimeMillis(); String name = Long.toString(n) + extname; 我通常是这样用的.. 急,快 安装tomcat 大家能来帮我么 谢谢 怎样将Unicode编码变化为对应字符 谁知道怎么在jcreator 中生成 javadoc enterprisedt ftp client & InterruptedIOException 从文本文件中读取数据,用向数据库中写入中文什么会变为乱码??谢了! 大量开发图书资料下载 请问,Java可以进行驱动程序的开发吗(Windows/Linux)? 添加classpath 有人使用NetBeans开发swing程序嘛? 安全机制一问 多态问题
重复了吧
GregorianCalendar c = new GregorianCalendar () ;
int year = c.get (Calendar.YEAR) ;
sUploadLocalDir = "\\download\\" + year + "\\" ; java.io.File myDir = new java.io.File (request.getRealPath (
sUploadLocalDir)) ;
if (!myDir.exists ())
{
myDir.mkdir () ;
} sFileName = myFile.getFileName () ;
//处理文件名
if (sFileName != null && !sFileName.equals (""))
{
String prefix = "" ;
String postfix = "" ;
int num = 0 ;
num = sFileName.lastIndexOf (".") ;
postfix = sFileName.substring (num + 1) ;
long now = System.currentTimeMillis () ;
prefix = String.valueOf (now) ; newFileName = prefix + "." + postfix ;
String filePath1 = request.getRealPath (sUploadLocalDir +
newFileName) ;
myFile.saveAs (filePath1, mySmartUpload.SAVE_PHYSICAL) ;
} //文件的上传处理完成
String name = Long.toString(n) + extname; 我通常是这样用的..