Results 1 to 6 of 6

Thread: Convert String to filename

  1. #1
    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.

  2. #2
    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.

  3. #3
    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.

  4. #4
    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());;
    			 }

  5. #5
    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();

  6. #6
    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.

Similar Threads

  1. Convert string into int in C
    By screwball in forum Software Development
    Replies: 4
    Last Post: 22-12-2011, 08:47 PM
  2. Convert XML string into DOM
    By GreatThinker in forum Software Development
    Replies: 6
    Last Post: 22-07-2010, 09:48 AM
  3. How to convert string into DateTime
    By Segvoia in forum Software Development
    Replies: 7
    Last Post: 05-03-2010, 02:55 PM
  4. convert string to number in asp.net
    By Texas in forum Software Development
    Replies: 3
    Last Post: 26-06-2009, 09:55 AM
  5. How to convert string to int
    By Zavier in forum Software Development
    Replies: 3
    Last Post: 04-06-2009, 06:24 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,626,147.11022 seconds with 16 queries