Primeiro, com base na implementação simples de leitura e gravação do arquivo, o método ReadFile na classe FileHelper é usado para ler o conteúdo do arquivo e o método WriteFile é usado para gravar conteúdo no arquivo.
importar java.io.bufferedReader; importar java.io.bufferedwriter; importar java.io.fileReader; importar java.io.fileWriter; public class FileHelper {public c static string readfile (string filename) lança excepção {bufferreader leitor = newredaderader (buffered bufferador ( novo fileReader (nome do arquivo)); ); (); Em seguida, escreva uma classe WebPagemaker baseada na classe FileHelper e seu método CreatePage é usado para gerar o conteúdo em um arquivo específico em uma página da Web específica.
Se você deseja inserir o código, poderá adicionar o código a ele.
importar java.util.stringTokenizer; public class WebPagemaker {public static string initbegin () {string s = "<! docttype html> <html> <head> <title> </t itle> </head> <body>/r /n "; return s;} public static string initend () {string s ="/r/n </body> </html>/r/n "; retorna s;} public static void createPage (string inputfilen AME, String OutputFilename) Exceção {String Content = FileHelper.Readfile (InputFilEname); while (St.HasMoreElements ()) {String S = St.NextToken (); len && s 5; i += 6; ; caso contrário, se (c == '/t') ANS += "" else ANS += c; /r/n ";} Ans += initEND (); fileHelper.WriteFile (Ans, outputFileName);} public static void main (string [] args) lança exceção {createPage (" d: // te st.txt ", "D: // test.html"); Amostra:
Arquivo de entrada: test.txt
Olá mundo! Olá a todos :) #include int main () {printf ("Hello World!/N"); Arquivo de saída: test.html
<! Doctype html> <html> <head> <title> </title> </head> <body> olá mundo! <r /> Olá a todos :) <BR /> <pre style = "Background-Color: AliceBlue"> Incluir <stdio.h> int main () {printf ("Hello World! /n"); } </pre> <r/> </body> </html> Os efeitos são os seguintes:
Olá mundo! Olá a todos :) #include <stdio.h> int main () {printf ("Hello World!/N");