cancel
Showing results for 
Search instead for 
Did you mean: 

File path issues while reading an xsl file in java

chandana_lakku
Explorer
0 Kudos

Hi,

I want to read an xsl file from a java class(which is located in a package com.a.b.c)

xsl file and the java class resides in the same package.(com.a.b.c)

The possible ways that i tried:

String xsltFile = "test.xsl";

String xsltFile = new File("test.xsl").toURL().toExternalForm( );

String xsltFile = new File("test.xsl").getAbsolutePath();

String xsltFile = new File("test.xsl").getPath( );

String xsltFile = "com/a/b/c/test.xsl"

All the above methods returns file path (where the application is deployed) but the actual xsl file doesn't exist there.

How should I read this "xsl file" from my java class which is located in the same path?

Could some one help me out on it?

Thanks & Regards,

Chandana.

Edited by: Chandana Lakku on Nov 25, 2009 7:52 AM

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Chandana,

Either move your .xsl file to the root directory of your package and use

new File("text.xsl");

, or leave the file where it is and use

new File("com/a/b/c/test.xsl");

.

Hope this helps.

Regards,

Alain

former_member193379
Active Contributor
0 Kudos

Chandana,

You can try the below code of a servlet.

import java.io.IOException;

import java.io.OutputStream;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import jxl.Workbook;

import jxl.write.Label;

import jxl.write.WritableSheet;

import jxl.write.WritableWorkbook;

public class Sample extends HttpServlet {

public void doGet

(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

OutputStream out = null;

try {

response.setContentType("application/vnd.ms-excel");

response.setHeader

("Content-Disposition", "attachment; filename=sampleName.xls");

WritableWorkbook w =

Workbook.createWorkbook(response.getOutputStream());

WritableSheet s = w.createSheet("Demo", 0);

s.addCell(new Label(0, 0, "Hello World"));

w.write();

w.close();

}

catch (Exception e){

throw new ServletException("Exception in Excel Sample Servlet", e);

}

finally{

if (out != null)

out.close();

}

}

}