我没说明白么?就是作一个程序。它读取一个html页面。然后把里面的
<img src="image/szzs.gif" width="778" height="97">改成
<img src="image/szzs.gif" width="778" height="97"/>
我是想得到程序的源代码。

解决方案 »

  1.   

    import java.io.FileInputStream;
    import java.io.FileOutputStream;public class TestConvert
    {
        public static void main(String[] args)
        {
            byte[] data = null;
            try
            {
                FileInputStream fis = new FileInputStream("a.html");
                data = new byte[fis.available()];
                fis.read(data);
                fis.close();
            }
            catch (Exception e)
            {
                e.printStackTrace();
                System.exit(1);
            }        String s = new String(data);
            String oldString = "<img src=\"image/szzs.gif\" width=\"778\" height=\"97\">";
            String newString = "<img src=\"image/szzs.gif\" width=\"778\" height=\"97\"/>";        StringBuffer buf = new StringBuffer();
            int start = 0;
            int end = s.indexOf(oldString);
            while (end != -1)
            {
                buf.append(s.substring(start, end));
                buf.append(newString);
                start = end + oldString.length();
                end = s.indexOf(oldString, start);
            }
            buf.append(s.substring(start, s.length()));        String result = buf.toString();        try
            {
                FileOutputStream fos = new FileOutputStream("b.html");
                fos.write(result.getBytes());
                fos.close();
            }
            catch (Exception e)
            {
                e.printStackTrace();
                System.exit(2);
            }
        }
    }
      

  2.   

    StringBuffer sb = new StringBuffer( "<img src=\"image/szzs.gif\" width=\"778\" height=\"97\">" );
            int pos1 = sb.indexOf( "<img" );
            int pos2 = sb.indexOf( ">", pos1 );
            sb.insert( pos2, '/' );
      

  3.   

    谢谢楼上的兄弟。:)也行我没说明白,我的本意是给定一个页面,
    我希望把里面的img标签后面都加上 ”/“,而不是对特定的标签才这样处理。
    请大家帮忙