Im giving the path of the image to properties file and getting the path to Image class in my pdfGenerating class. like:
properties.load(DownloadPdf.class.getResourceAsStream("/resource.properties"));
System.out.println("--properties----"+properties);
System.out.println("-path-"+properties.getProperty("logoPath"));
//String path = properties.getProperty("logoPath");
//URL uri = Paths.get(path).toUri().toURL();
System.out.println("---path-"+properties.getProperty("logoPath"));
Image image = Image.getInstance(properties.getProperty("logoPath"));
Here my logopath is:
path----------------C:/Users/Home/Documents/workspace-gofindo/.metadata/.plugins/org.eclipse.wst.server.core/.....
But i'm getting the path in
Image.getInstance(properties.getProperty("logopath"));
like
C:\Users\Home\Documents\workspace-gofindo\.metadata\.plugins\org.
I have tried with replace and replaceAll() methods to convert '\\' to '/' again the image class converting into '\\'. How to get my absolute path which i have specified in properties file exactly into Image.getInstance() method
I have remodified the way i can read the path of the file like below.
// Load path of the Image from Properties file
Properties properties = new Properties();
properties.load(this.getClass().getResourceAsStream(
"/resource.properties"));
// To get the Path of the Context
String contextPath = request.getContextPath();
String split_path[] = contextPath.split("/");
contextPath = request.getRealPath(split_path[0]);
Image image = Image.getInstance(contextPath
+ properties.getProperty("logoPath"));
image.scaleAbsolute(120f, 60f);// image width,height
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.