I am making a graph using jfreechart library. By default is generate it in Temp folder of window now i want to past it in my
tomcat project folder i use the following code, but it does not work.
File tempDir = new File(System.getProperty("java.io.tmpdir")); // to get temp directory path
String temp1 = tempDir.getCanonicalPath();
String graphName= request.getParameter("graphName");
File file;
file = new File(graphName);
String ADVERT_IMAGE = file.getName();
String ad_IMAGE = ADVERT_IMAGE.split(".jpeg")[0];
String fileName = ad_IMAGE;
try
{
String ServletPath = request.getServletPath();
String ServletName = ServletPath.substring(1);
String ServletPathReal = application.getRealPath(ServletPath);
String sep = "";
if(ServletPathReal.indexOf("\\") > 0)
{
sep = "\\";
}
else
{
sep = "/";
}
String ReportPath = ServletPathReal.substring(0, ServletPathReal.lastIndexOf(sep)) ;
String rootPath = ReportPath.substring(0, ReportPath.lastIndexOf(sep));
String rootFolder = rootPath + sep + "Admin"+ sep + "Upload" + sep + "Graph" + sep;
String rootAdmin = ".." + sep + "Admin"+ sep + "Upload" + sep + "Graph" + sep;
ad_IMAGE = rootAdmin + fileName +".jpg";
//**********************************
File folder=new File(rootFolder);
if(!folder.exists())
{
boolean success = (new File(rootFolder)).mkdir();
if (!success) {
throw new Exception("Directory not found.");
}
}
int sizeLimit = 5; // in terms of MB
MultipartRequest multi = new MultipartRequest(request, rootFolder , sizeLimit * 1024 * 1024);
Enumeration params = multi.getParameterNames();
while (params.hasMoreElements())
{
String name = (String)params.nextElement();
String value = multi.getParameter(name);
}
Enumeration files = multi.getFileNames();
while (files.hasMoreElements())
{
String name = (String)files.nextElement();
boolean status = renameFile(fileName,multi.getFile(name), rootFolder, sep);
if (status == false)
{
boolean del = replaceFile(fileName,multi.getFile(name), rootFolder, sep);
if(del == false)
throw new Exception("Error while replacing file~");
}
}
}
Any one can help me in this regard.