I was wondering if this was possible in Java. I posted this in a vb forum since vb seemed pretty easy at the time. I finally decided that I would have to learn a lot of stuff just to be able to do this. So, since I'm currently taking a Java course I thought it might be easier to do with a language that I at least have some understanding of. Following are the things that I need my program to do. Thanks a lot for any help at all that can be provided. - I need a browse button where the user can specify the directory and file. - I need to then rename that file from whatever the extension may be to an extension of .xml (foo.txt -> foo.xml) - I then need someway of accessing the file and finding "standalone='yes'", then changing it to "standalone='no'" - Lastly, I need to open this new file with it's default program
Hello Andrew, Welcome to JavaRanch. Here are some quick answers to your questions. I was wondering if this was possible in Java. Yes. I finally decided that I would have to learn a lot of stuff just to be able to do this. I'm afraid you'll find the same is true in Java, or any other language. There is no quick and easy lay way to do what you are looking to do. You'll need to learn about and understand several different APIs. I need a browse button where the user can specify the directory and file. Java has a built in class for doing such - javax.swing.JFileChooser - take a look at the Java API and Sun's Tutorial on the JFileChooser for more information. I need to then rename that file from whatever the extension may be to an extension of .xml (foo.txt -> foo.xml) If you search the I/O and Streams forum here at the ranch for "copy file" and "rename file" you will find plenty of threads discussing how to do that. I then need someway of accessing the file and finding "standalone='yes'", then changing it to "standalone='no'" If the document is true XML, you could use an XML parser (either the one built into the JDK or a third party library). Otherwise you could do a more basic search & replace. Again, search the I/O forum and you should be able to find a starting point. If you run into troubles, make a post stating the issues you are having and someone can help you out. Lastly, I need to open this new file with it's default program Are you asking how to have your Java Application open the file in its default program? [ February 06, 2004: Message edited by: Mark Vender ]
Joined: Feb 05, 2004
Thanks a lot for your help, i'll look into all of that. Pertaining to your last question, yes I would like to be able to do it from the java application.
Joined: Dec 10, 2001
Andrew, you'll likely prefer figuring this program out one small part at a time. Folks around here will be able to point you in the right direction to help get started at times, and they'll be able to help figure out some small part that's giving you problems after you've started to write the program. So, I suggest you pick some small part to start on and then start writing the program. As you come across things that you just cannot figure out, ask about them. Perhaps figuring out how to use a java.awt.FileChooser or a javax.swing.JFileChooser to select a file would be a good place to start. Shortly after that would probably be a good time to figure out renaming a file using java.io.File.renameTo(java.io.File).