-
Renaming within files
Hi,
I was just wondering how you would go about creating a java program that would find all .html files in a folder and rename them to .jsp files? And the program would also find any .html links within the .html files and change them to .jsp?
Anyone got any help PLEASE
Thanks Very Much
-
The files can be located using the File class' list method in conjunction with the filename filter interface. The parsing of html files can be done using java's html parser utilities.
I would have posted some code samples if it hadn't been for the fact that I have been offline since february and won't have my "library" pc online until mid april (moving to new house is a real drag )
eschew obfuscation
-
Adding a line
I wish to add the line "<jsp:include>" onto "page1.jsp". Bt using the code below it adds it on to the top of it but deletes everyting else from the file? Any ideas on how to fix this please?
import java.io.*;
public class ScanFar {
public static void main(String[] args) throws IOException {
File inputFile = new File("page1.jsp");
File outputFile = new File("page1.jsp");
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
out.write("<jsp:include>");
while ((c = in.read()) != -1)
out.write(c);
in.close();
out.close();
}
}
-
Quote from Javadocs:
FileWriter
public FileWriter(File file,
boolean append)
throws IOException
Constructs a FileWriter object given a File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning.
Parameters:
file - a File object to write to
append - if true, then bytes will be written to the end of the file rather than the beginning
Throws:
IOException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
Since:
1.4
Use this constructor to append to the file. The constructor you are currently using will overwrite the file!
Kind regards,
Noel
Efficiency is intelligent laziness
Similar Threads
-
By JohnsenJu in forum VB Classic
Replies: 26
Last Post: 03-30-2006, 05:11 PM
-
By C++Monkey in forum C++
Replies: 12
Last Post: 01-21-2006, 03:22 AM
-
By DaveMere in forum VB Classic
Replies: 5
Last Post: 07-14-2005, 12:44 PM
-
Replies: 8
Last Post: 08-23-2002, 04:35 PM
-
By René Whitworth in forum vb.announcements
Replies: 1
Last Post: 04-29-2000, 02:54 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|