how to give the default path in gwt - gwt

i m creating a project in gwt (point) is project name ...
i want to store a image in point/war/images folder, whaich i gave the full path like C:\Documents and Settings\computer\workspace\m\war\images\ tthe the iamge will stored in images folder but i want to give the default path
i give "../war/images/" as default path, but this give me error (he system cannot find the path specified )
can any body help to give the default path

Usually you put images in the war/images directory, and you access them like
Image img = new Image("images/my_image.jpg")
You may also read this thread, and this question.

Related

Loading file using a path writen in edit box matlab

hello evryone
wanna load file from a specific path writen in an edit box named by 'Load_text', i got the path from the edit box using :
pth=get(handles.Load_text,'string');
then i used 'dir' as follow:
S=dir(fullfile([pth '*.bmp']));
that what cause me an errur . so any ideas ?
If you want to load a file then why you are using dir?
Since you have the file's name, then you can create the fullpath as you do with the fullpath method and check its existence with exists.
If the file exists, then you can load it with all available methods from MATLAB.
Keep in mind that this means that the file is in the same directory as your GUI files. If it is in another then you will have to add it in the fullpath call.
fullpath online doc: http://www.mathworks.com/help/matlab/ref/fullfile.html
exists online doc: http://www.mathworks.com/help/matlab/ref/exist.html

Accessing image from a specific folder in matlab

Can someone please explain to me what the code below isnt working?
myFolderdepth = 'C:\Users\owner\Desktop'; %Specify Directory to get image from
Depth = dir (fullfile(myFolderdepth,'shower_depth','*.png'))%%Get images from file named shower_depth
Depth_name = {Depth.name}'; %gets the name
figure;
imshow(Depth_name{3})
The error message I get is as follows:
Error using getImageFromFile (line 11)
Cannot find the specified file:
"Depth_003.png".
The directory I am working in is: C:\Users\owner\Desktop
The name of the pictures are Depth_001,Depth_002,Depth_003,......
Oddly enough, I have another folder that has images and if I change the 'shower_depth' to the other folder name, it works fine.
Thank you!
P.S I did some further experimentation, it turns out its because of the way the image is named; if its Depth_01.png thats fine it works but Depth_001.png is not okay
Anyone knows why?
The following command:
Depth = dir (fullfile(myFolderdepth,'shower_depth','*.png'))
only gets the relative names of the files. This means that the file names are only retrieved, not the full path to the file. Take a look at the error that you're getting:
Error using getImageFromFile (line 11)
Cannot find the specified file: "Depth_003.png".
Do you see the path of where your images in the above file name? Nope! You only see the file stored in the directory. You need to specify the full path of where the image is located.
What you need to do is append the directory as well as the image itself as the string you supply to imshow:
myFolderdepth = 'C:\Users\owner\Desktop'; %Specify Directory to get image from
Depth = dir (fullfile(myFolderdepth,'shower_depth','*.png'))%%Get images from file named shower_depth
Depth_name = {Depth.name}'; %gets the name
figure;
imshow(fullfile(myFolderDepth, Depth_name{3})); %// CHANGE HERE
Depth_name is only the image name. You have to read the image before show it. The modified code is below:
im = imread(Depth_name{3});
imshow(Depth_name{3});

Difficulty using BufferedImage in Eclipse

I have stored an image in a Resource folder 'Images':
src
-com.program
-Images
In the program I use
BufferedImage image =ImageIO.read(getClass().getResourceAsStream("/myImage.png"));
to import the image.
This works fine. However, if i change the name of the image at the source(say to myImage1.png)
and try to execute
BufferedImage image =ImageIO.read(getClass().getResourceAsStream("/myImage1.png"));
I get Input==Null.
I've been try to get this to work for a while and tried various suggestions on other threads.
Any ideas?
Thanks!
The problem was most likely:
The image was in your src folder inside your project, but when the program runs, it runs from another folder containing your compiled classes. This folder did not contain the png, so you get the input == null exception (getClass().getResourceAsStream(...) returns null when resources cannot be resolved).
To make it work, you need to mark the images folder a resource folder (using Eclipse, Maven or favorite build tool), and make sure that the contents of that folder is on your class path when the program is run.

Exporting an JAR file in Eclipse and referencing a file

I have a project with a image stored as a logo that I wish to use.
URL logoPath = new MainApplication().getClass().getClassLoader().getResource("img/logo.jpg");
Using that method I get the URL for the file and convert it to string. I then have to substring that by 5 to get rid of this output "file:/C:/Users/Stephen/git/ILLA/PoC/bin/img/logo.jpg"
However when I export this as a jar and run it I run into trouble. The URL now reads /ILLA.jar!/ and my image is just blank. I have a gut feeling that it's tripping me up so how do I fix this?
Cheers
You are almost there.
Images in a jar are treated as resources. You need to refer to them using the classpath
Just use getClass().getResource: something like:
getClass().getResource("/images/logo.jpg"));
where "images" is a package inside the jar file, with the path as above
see the leading / in the call - this will help accessing the path correctly (using absolute instead of relative). Just make sure the path is correct
Also see:
How to includes all images in jar file using eclipse
See here: Create a file object from a resource path to an image in a jar file
String imgName = "/resources/images/image.jpg";
InputStream in = getClass().getResourceAsStream(imgName);
ImageIcon img = new ImageIcon(ImageIO.read(in));
Note it looks like you need to use a stream for a resource inside an archive.

eclipse: Find Resource with a locationURI

How can i find a Resource with a locationURI?
Path path = new Path('/home/foo/eclipse/runtime-EclipseApplication/someproj/B.txt');
IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
I know there is a way by using the locationURI from current project to trim the "needless" part, but is there a "better" way to slove this issue.
You can use the following construction:
ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(URIUtil.toURI(fileName));
where fileName - absolute path of File.getAbsolutePath()
and URIUtil from org.eclipse.core.filesystem
You can use a FileLocator to find the file within your bundle, if that is what you want (instead of finding a file in the runtime workspace), see Retrieve a file from within a folder in the workspace