private static String getUniqueId()
{
int current;
synchronized (DefaultFileItem.class)
{
current = counter++;
}
String id = Integer.toString(current);
if (current < 100000000)
{
id = ("00000000" + id).substring(id.length());
}
return id;
}
private static String getUniqueId()
{
int current;
synchronized (DefaultFileItem.class)
{
current = counter++;
}
String id = Integer.toString(current);
if (current < 100000000)
{
id = ("00000000" + id).substring(id.length());
}
return id;
}
1.不要用""+整数来拼接字符串。调用Integer.toString高效
2.公有数据加同步保护
protected File getTempFile()
{
File tempDir = this.repository;
if (tempDir == null)
{
tempDir = new File(System.getProperty("java.io.tmpdir"));
}
String fileName = "upload_" + getUniqueId() + ".tmp";
File f = new File(tempDir, fileName);
f.deleteOnExit();
return f;
}
注意删除f.deleteOnExit在jvm退出的时候删除文件
fileupload源码分析
猜你喜欢
转载自daybyday.iteye.com/blog/1076030
今日推荐
周排行