Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Copy a picture from temp folder to another folder  RSS feed

 
ehsan ulhaq dar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Goutham Pallipati
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

There is no information on what you are doing in renameFile method.
boolean status = renameFile(fileName,multi.getFile(name), rootFolder, sep);

But check the fileName part. fileName contains only the firstName without extension.

Also why are you using MultipartRequest for doing local file operations is it like you are uploading from page the charts created in temp dir??

File file;
file = new File(graphName);
String ADVERT_IMAGE = file.getName();
String ad_IMAGE = ADVERT_IMAGE.split(".jpeg")[0];
String fileName = ad_IMAGE;
 
ehsan ulhaq dar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No basically i am generating a graph which is generated in temp folder and i can't use it in jsp page because at client side it path is like
C:\Documents and Settings\Administrator\Local Settings\Temp\graph.jpg
and it is not recognize at client side so i just want to copy it in tomcat project folder.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!