Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Convert String to filename

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 12-03-2010
Member
 
Join Date: Mar 2010
Posts: 222
Convert String to filename
  

Hello,
I have a recording path + filename in an ArrayList type.
Code:
C: \ Documents and Settings \ xxxxxxxxx \ Desktop \ Xml \ xxxxxxxxxxxxx.xml
I then put all these data into a file. I do that, but it has ps seem to work
Here is the code
Code:
			File[] fllst = null;
			for(int i =0; i <filename.size(); i + +){
				 fllst[i]=(File) filename.get(i);
			}
My problem is that I need to convert the String to in the file name. Is this possible in java and if yes the please help me with this. Thanks in advance.

Reply With Quote
  #2  
Old 12-03-2010
Member
 
Join Date: Nov 2009
Posts: 359
Re: Convert String to filename

Hello,
The following code may work better that the one which you are using.
Code:
File [] = fllst null;
 for(int i =0; i <x.size (); i + +) (
 fllst [i] = new File (x.get (i));
 )
Hope the code will help you.
Reply With Quote
  #3  
Old 12-03-2010
Member
 
Join Date: Nov 2009
Posts: 356
Re: Convert String to filename

Hello,
After the javadoc if you get a NullPointerException is that the value that you pass when you built your File is null. But what you want to create a list of File or you want to copy all your paths in a File is not very clear. I guess you have understood the concept here and if you need more help on this then you can visit the sun's official site and find more detailed information on the same.
Reply With Quote
  #4  
Old 12-03-2010
Member
 
Join Date: Nov 2009
Posts: 518
Re: Convert String to filename

Hey
See if this method can help you.
Code:
if (ch.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
			 {
			 File fl[] = ch.getSelectedFiles();
String file ="";
			 for (int i =0, n = fl.length; I <n; i + +) {
				 file = fl[i].getName()+"\ n"+ file;
Stocknm(fl[i].getAbsolutePath());;
			 }
Reply With Quote
  #5  
Old 12-03-2010
Member
 
Join Date: Nov 2009
Posts: 347
Re: Convert String to filename

Hello,
This is the full code and will help you for sure, check it out
Code:
Public static void Process(File[] lsfl){
		try {
		      for(int i = 0; I <lsfl.length; I + +){		      
		    	  System.out.System.out.println("Target name" + lsfl[i].getName());
String shortname = (lsfl[i].getName() != null) ? lsfl[i].getName().substring(0, lsfl[i].getName().indexOf('.')) : "";
j + +;
System.out.System.out.println(lsfl[i].getAbsolutePath());
 
		    	 
			/ / build XML file
			DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
fac.setNamespaceAware(true);
DocumentBuilder parser = fac.newDocumentBuilder();
					
			/ / create the XML file
			Document d = parser.parse(new File(lsfl[i]..getAbsolutePath()));
DOMSource sourceXML = new DOMSource(d);		
	          			
			/ / Create the XSL file
			d = parser.parse(Hand.class.getResourceAsStream("Transformation.xsl"));
DOMSource src = new DOMSource(d);

TrFact = TransformerFactory TransformerFactory.newInstance();
trns trns = trFact.newTransformer(src);
trns.setOutputProperty(OutputKeys.Method, "html");
trns.setOutputProperty(OutputKeys.Encoding, "ISO-8859-1");
trns.setOutputProperty(OutputKeys.INDENT, "yes");
			
/ / Transformeur.setParameter ( "num", "6");
			
			File fl1 = new File(shortname +. vm ");

FileOutputStream fos = new FileOutputStream(fl1);
			
			if (fos! = null) {
				Result out = new StreamResult(fos);
trns.transform(sourceXML exit);
							}			
			fos.flush();
fos.close();
Reply With Quote
  #6  
Old 12-03-2010
Member
 
Join Date: Nov 2009
Posts: 446
Re: Convert String to filename

Hello,
Creating a file with a name is always being in the working directory of your application. If you want to put it in another directory, use:
- New File ( "absolute path to your file")
- New File ( "relative path to your file from your working directory")
I guess you have got a good idea of how to do this and you will successfully implement this in your code.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Convert String to filename"
Thread Thread Starter Forum Replies Last Post
Convert string into int in C screwball Software Development 4 22-12-2011 08:47 PM
Convert XML string into DOM GreatThinker Software Development 6 22-07-2010 09:48 AM
How to convert string into DateTime Segvoia Software Development 7 05-03-2010 02:55 PM
convert string to number in asp.net Texas Software Development 3 26-06-2009 09:55 AM
How to convert string to int Zavier Software Development 3 04-06-2009 06:24 PM


All times are GMT +5.5. The time now is 11:35 PM.