Hello everyone,
I was testing a web app on Tomcat and I basically created a 'Temp' folder in the 'Web-content' folder of the project in Eclipse. I write files to that folder in my web app by using the following code: -
String imagePath = getServletContext().getRealPath("/Temp/")+"\\"+userName+".png";
-
After doing this, I was able to download the file from http://localhost:8080/MyProjectName/Temp
When I switched to JBoss for the same application without making any changes, and after creating the 'Temp' folder in the same location, I keep facing a 'file not found' exception when I try to use the following code: -
String imagePath = getServletContext().getRealPath("/Temp/")+"\\"+userName+".png";
-
ImageIO.write((BufferedImage)returnValue, "jpg", new File(pathOfChart+"chart.jpg"));
-
It says 'The system could not find the path specified'.
Does anyone know why this is happening and/or how I could work around this?
Thanks in advance for your help.
Cheers.
Nikhil
9 10454
Don't use \\ for path separator in Windows? Always use \ for File Path Separator.
JosAH 11,448
Recognized Expert MVP @dmjpro
The poster is using a single back slash; it needs to be escaped in String literals.
kind regards,
Jos
@JosAH
<snipped> ............. Actually it would be , "always use / " ;)
I worked around that problem by creating a directory (if it doesn't automatically exist) at the servlet's start up. A "filePointer.mkdirs()" seemed to take care of that just fine. The same code works with that. Just thought I would put this up if anyone else faces a similar problem. Thanks for your help.
Regards,
Nikhil
@ne0lithic
See, Have the code like this ... -
String imagePath = getServletContext().getRealPath("/Temp/")+userName+".png";
-
Here i can see two paths you are using ...
1.imagePath
2.pathOfChart
Print two paths, and see what it results ;)
Use / always as "file path separator" what ever OS or server you are using.
First let me know which path the "System can't find" and what are print outs of "two paths". Check whether two paths exist or not.
Instead of using / or \, the best way (os-independent) is to use "File.separator" !
Always using / is not os-independent!
Yeah.. I Know.
I think if i put / then it would be running on any OS so far what implemented. Basically Windows offer \ and rest offers /.
But if you put / for Windows then Java can intelligently make it Windows compatible ;)
FYI, I tried printing the path when I had the earlier problem and it showed now problems whatsoever. If I hard-coded the path in the system (say "D:/Something/Somewhere") that would work just fine.
You are defining variable "imagePath", but don't use it!
Instead, you use "pathOfChart".
So why don't you print out these values and show them to us, or list the whole source code?
The calculation of imagePath seems correct.
You wrote if you hardcode the whole path it works.
So I guess the error is somewhere how you calculate "pathOfChart". Maybe it doesn't contain a backslash at the end? (it must, because you are concatenating directly the image name to it.)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Ricky |
last post by:
My question:
If I have a mapped driver letter g: that referes to
\\servername\d\foldername
How do I get java to convert it from g: to the real path so I can use
it?
I have a script that allows someone to locate a file on the server,
but most will use there mapped drives as they know nothing better.
|
by: Chris Gatto |
last post by:
Hello,
My organization is currently considering the purchase of a new intranet
application server and we are looking for opinions from those who have been
down this road before. In brief the server must support the following:
- 600+ users using various ASP.Net based applications, only 2 currently but
growing over time as old legacy apps...
|
by: Ann Huxtable |
last post by:
Hi,
I am developing a C# front end. But my backend app server is JBoss. I
want to know how I can communicate with the backend (maybe using
System.Net.WebClient classes?). A search on Google does not yield much.
I look forward to any one who has actually done this in practise, or
failing that, any suggestions of how to solve this would be...
|
by: Jochen Fromm |
last post by:
In the Java and J2EE world there are quite a few application servers like
WebShpere, WebLogic or JBoss if you want to develop large-scale
applications. How many pure .NET application server exist which are not
based on old COM or COM+ technology ? Would it make sense to develop a new
one, with special emphasis on self-* properties,...
|
by: den 2005 |
last post by:
Hi everybody,
I like to allow user to select and browse to which location to save the
pdf file of a crystal report viewed on a web page, how can i do this in
ASP.Net? I need to get the path selected from dialog box. Thanks.
Note: Using VS 2002
den2005
| |
by: Vincent Delporte |
last post by:
Hello
I'm interested in hearing reflections by seasoned web app
developpers about the different ways to write PHP apps, and especially
how they compare in terms of performance, whether it's the PHP part or
connections to MySQL.
As far as I know, there are different ways to write a PHP application:
- CGI, ie. the usual way : some PHP code...
|
by: mastery20 |
last post by:
hi gurus,
i have downloaded jboss 4.0.2 in zip format and i have checked it in ie by giving the url:localhost:8080/jmx-console.when i am trying to execute ant it is not.In command mode when i compiled by ant -f jboss-build.xml compile it gives an error msg stating that "ant is not recognised as internal or external command [/B" .
plz help me.wat...
|
by: rh00667 |
last post by:
hi all,
i'm confused now. how i can get the full path of an application?
if myapp is in a directory which belongs to PATH, argv gives me the
first token of cmd line, and not the real path of the executed
program.
so if i write anywhere:
|
by: walterbyrd |
last post by:
Can somebody help me understand the difference? Not just where Python
is concerned, but in general?
As I understand it, an application server is supposed to be a great
help in developing apps, because most of the business logic is already
there. It seems to me that, usually when applications servers are
discussed, people are talking about...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |