kumare
asked on
write a file on unix box
I have a java web application on weblogic which is on unix box. I am opening a file like this
File temp = new File("test.bmp"); and writing an image into it in servlet A.
The file is been written at some default location. When I try to read the file back in servlet B i am getting an exception Exception: Can't read input file!
How do we store/read from unix in java
File temp = new File("test.bmp"); and writing an image into it in servlet A.
The file is been written at some default location. When I try to read the file back in servlet B i am getting an exception Exception: Can't read input file!
How do we store/read from unix in java
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
does the explicit path relative to the root directory of the webapplication
can you provide the code bit that you are currently using for Servlet A and Servlet B...it would be a lot easier to solve your problem!
Seervlet is like any program ruinning on your unix box - so put the absolute path there - makes sure you have privuileges to write there
It is the other way around - in acse you need then from the context ovject you can find the absolute path of your root.
But for this sirtuation you don;t need any of that - jus put there absolute path to your file as you see it on command line termianl on the same host
and wervlet wuill write there
But for this sirtuation you don;t need any of that - jus put there absolute path to your file as you see it on command line termianl on the same host
and wervlet wuill write there
ASKER
Somehow the servelt is not able to display the image .. on browser it says image cannot be displayed as it contains errors
PrintWriter out = res.getWriter();
res.setContentType("image/ jpeg");
File temp = new File("//opt//app//temp//te st.bmp");
BufferedImage image= ImageIO.read(temp);
out.print(image);
PrintWriter out = res.getWriter();
res.setContentType("image/
File temp = new File("//opt//app//temp//te
BufferedImage image= ImageIO.read(temp);
out.print(image);
servlet can send the http page with the link to ithe imgae to the browser - but that is absolutely diofferent thing from waht we were talking about bfefore
If you want to write the image and dispaly it to the lcien on the web page then you need to know the root of the documents of
of your web server - gthen you write to some folder under this root folder (and when you are wrtiting in the servlet the bmp file - you can use the
fiull path on the host to that folder) but the you should place the link in yourt htto - and here it should have path in the link starting form your
root dociument folder - let me know if you undrstand that
of your web server - gthen you write to some folder under this root folder (and when you are wrtiting in the servlet the bmp file - you can use the
fiull path on the host to that folder) but the you should place the link in yourt htto - and here it should have path in the link starting form your
root dociument folder - let me know if you undrstand that
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it might be one solution but I think the way I have done it should also be working ..but something is preventing it from displaying.
I'm not sure you can do it the way you done it.
taht is how i alays send images to webpages is throuh link in the HTML page
taht is how i alays send images to webpages is throuh link in the HTML page
>>
PrintWriter out = res.getWriter();
res.setContentType("image/ jpeg");
File temp = new File("//opt//app//temp//te st.bmp");
BufferedImage image= ImageIO.read(temp);
out.print(image);
>>
That's not going to work and is functionally meaningless. If your objective is to display the image, then you need to do that in the normal way by including the correct path to it in an <img> tag
PrintWriter out = res.getWriter();
res.setContentType("image/
File temp = new File("//opt//app//temp//te
BufferedImage image= ImageIO.read(temp);
out.print(image);
>>
That's not going to work and is functionally meaningless. If your objective is to display the image, then you need to do that in the normal way by including the correct path to it in an <img> tag
otoh, if you want to *download* the image, that would be different again. What is your goal?
ASKER
I had the following solution in end. my opjective was to just spit out the image on the browser
ServletOutputStream sos = res.getOutputStream();
res.setContentType("image/ jpeg");
File temp = new File("//opt//app//test.bmp ");
byte[] b = new byte[(int) temp.length()];
FileInputStream fileInputStream = new FileInputStream(temp);
fileInputStream.read(b);
ByteArrayOutputStream baos = new ByteArrayOutputStream(b.le ngth);
baos.write(b);
baos.writeTo(sos);
sos.flush();
ServletOutputStream sos = res.getOutputStream();
res.setContentType("image/
File temp = new File("//opt//app//test.bmp
byte[] b = new byte[(int) temp.length()];
FileInputStream fileInputStream = new FileInputStream(temp);
fileInputStream.read(b);
ByteArrayOutputStream baos = new ByteArrayOutputStream(b.le
baos.write(b);
baos.writeTo(sos);
sos.flush();
And you can spacify explisit path in you new File(...)
then you'll have no problems with that