Renaming within files


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Renaming within files

  1. #1
    Join Date
    Apr 2006
    Posts
    3

    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

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    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

  3. #3
    Join Date
    Apr 2006
    Posts
    3

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

  4. #4
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    62
    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

  1. Help with renaming files
    By JohnsenJu in forum VB Classic
    Replies: 26
    Last Post: 03-30-2006, 06:11 PM
  2. Renaming Files
    By C++Monkey in forum C++
    Replies: 12
    Last Post: 01-21-2006, 04:22 AM
  3. Renaming text files in VB
    By DaveMere in forum VB Classic
    Replies: 5
    Last Post: 07-14-2005, 01:44 PM
  4. XML files vs Database
    By Mansoor in forum XML
    Replies: 8
    Last Post: 08-23-2002, 05:35 PM
  5. Replace In Files utility released
    By René Whitworth in forum vb.announcements
    Replies: 1
    Last Post: 04-29-2000, 03: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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center