Results 1 to 12 of 12
- 12-06-2011, 05:39 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 11
- Rep Power
- 0
Hello All a little List question...
Hello All...
File[] files = fd.getSelectedFiles();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < files.length; i++)
{
sb.append(files[i].getPath() + "\n");
list.add(sb.toString());
}
This just gets the file and their paths to a list.
I am trying to extract items from this list with;
String Path = list.getItem(0);
But unfortunately i can not convert the string to a filepath...
which i am going to use in;
RenderedImage image = (RenderedImage)JAI.create("fileload",ImPath);
Is there a way?
i looked at some conversions even with stream one but unfortunately it does not allow as a path...
regards
ömer kaya
METU
- 12-06-2011, 05:56 PM #2
Re: Hello All a little List question...
Please explain the problemi can not convert the string to a filepath...
Have you printed out the String to see what it contains?
Very few Strings are valid filepaths.
- 12-06-2011, 05:59 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Hello All a little List question...
What do you mean by "i can not convert the string to a filepath"?
What happens when you use it as a path?
The way you are creating your List is incorrect as well.
Print out the contents of your List after you have filled it and see what I mean.
- 12-06-2011, 06:14 PM #4
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
Re: Hello All a little List question...
Are you sure you know what StringBuilders append method does?
StringBuilder (Java Platform SE 6)
- 12-07-2011, 09:03 AM #5
Member
- Join Date
- Dec 2011
- Posts
- 11
- Rep Power
- 0
Re: Hello All a little List question...
Hello again sorry for the late response.
"C:\Users\Public\Pictures\Sample Pictures\1296.jpg"
this is the output from;
String Path = list.getItem(0);
printed to the console as;
System.out.println(Path);
String builder is what i used to divide the selection of files with the multi selection. and write them in the list separated from each other. Hope i am using it correctly.
Thanks for a lot of responses.
Waiting.
- 12-07-2011, 09:43 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Hello All a little List question...
And what does list.get(1) contain?
Or list.get(2)?
Because, from that code up there, they are going to be quite different from what you intend.
- 12-07-2011, 09:50 AM #7
Member
- Join Date
- Dec 2011
- Posts
- 11
- Rep Power
- 0
Re: Hello All a little List question...
Hello;
They contain same listings as the getitem(0)
just raw paths. as windows understands
nothing more.
kind regards
ömer kaya
- 12-07-2011, 09:52 AM #8
Member
- Join Date
- Dec 2011
- Posts
- 11
- Rep Power
- 0
Re: Hello All a little List question...
sorry for not telling but.
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: "C:\Users\Public\Pictures\Sample Pictures\1296.jpg": File not found.
this is the exception i am getting. the path is valid and the file is there.
thanks a lot.
ömer kaya
METU
- 12-07-2011, 10:24 AM #9
Member
- Join Date
- Dec 2011
- Posts
- 11
- Rep Power
- 0
Re: Hello All a little List question...
at javax.media.jai.JAI.createNS(JAI.java:1087)
at javax.media.jai.JAI.create(JAI.java:973)
at javax.media.jai.JAI.create(JAI.java:1408)
if it matters these are the external library exceptions.
- 12-07-2011, 11:40 AM #10
Member
- Join Date
- Dec 2011
- Posts
- 11
- Rep Power
- 0
Re: Hello All a little List question...
Hello All;
Found my problem.
I was doing it wrong.
sb.toString makes the item that i add to the list as a string. So that when i try to get the file out of it it takes as string.
when i deleted this and use it as just another object it gets it as a path as originally stated.
so my code was changed like;
if ( status == JFileChooser.APPROVE_OPTION )
{
File[] files = fd.getSelectedFiles(); // Chosen Path's are going to be stored to a array list.
StringBuilder sb = new StringBuilder(); // String Builder is the class for converting the array into divided strings of choice.
for (int i = 0; i < files.length; i++) // Reading the files array
{
// Dividing path strings in respect of selected files.
list.add(files[i].getPath()); // Converting to strings <List.Add accepts only Strings>
}
}
else if (status == JFileChooser.CANCEL_OPTION )
{
System.out.println("Cancel Selected");
}
else
{
System.out.println("Selection Error");
}
And Image Showing as
String ImPath = list.getItem(0);
//ystem.out.println(ImPath);
RenderedImage image = (RenderedImage)JAI.create("fileload",ImPath);
int width = image.getWidth();
int height = image.getHeight();
System.out.println(width);
System.out.println(height);
ScrollingImagePanel panel = new ScrollingImagePanel(image, 512, 512);
Frame window = new Frame("Scrolling Image Panel Example");
window.add(panel);
window.pack();
window.show();
Thanks a lot all...
regards
ömer kaya
METU
- 12-07-2011, 11:54 AM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Hello All a little List question...
That code int he OP does not do that:
The above produces:Java Code:import java.util.ArrayList; import java.util.List; public class Scratch { /** * @param args */ public static void main(String[] args) { String[] strings = {"First one", "Second one", "Third one"}; List<String> stringList = new ArrayList<String>(); StringBuilder sb = new StringBuilder(); for (String s : strings) { sb.append(s); stringList.add(sb.toString()); } for (String s : stringList) { System.out.println(s); } } }
First one
First oneSecond one
First oneSecond oneThird one
So each file path after the first had no hope of being correct.
Anyway, good to see you corrected your problem.
- 12-07-2011, 12:36 PM #12
Member
- Join Date
- Dec 2011
- Posts
- 11
- Rep Power
- 0
Re: Hello All a little List question...
Thanks a lot Tolls.
the problem was the file path <As JAVA Knowns "C:\\...\\[filename]" is stored to the list array but i forced to convert it to a string.
So that when i asked for the information it returned to me as string not path of file.
When i deleted the string from it that gave me the right answer.
This was the problem.
Thanks a lot for the interest.
regards
ömer kaya
METU
Similar Threads
-
a linked list question
By smacker in forum New To JavaReplies: 5Last Post: 05-04-2011, 12:57 PM -
Question for a list of objects
By johnhelen in forum New To JavaReplies: 4Last Post: 02-17-2011, 09:23 PM -
List question, I don't understand why...
By jigglywiggly in forum New To JavaReplies: 14Last Post: 03-21-2010, 08:59 AM -
A simple List question
By right2001 in forum New To JavaReplies: 2Last Post: 02-16-2009, 03:37 AM -
Linked List Question
By CirKuT in forum New To JavaReplies: 4Last Post: 12-10-2008, 06:56 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks