|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
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 Here is the code Code: File[] fllst = null; for(int i =0; i <filename.size(); i + +){ fllst[i]=(File) filename.get(i); } |
#2
| |||
| |||
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)); ) |
#3
| |||
| |||
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
| |||
| |||
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
| |||
| |||
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
| |||
| |||
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. |
![]() |
|
Tags: convert, datatypes, filename, input, javaio, output, string |
Thread Tools | Search this Thread |
|
![]() | ||||
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 |