• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Copy a picture from temp folder to another folder

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic