00001
00005 import java.io.BufferedReader;
00006 import java.io.FileReader;
00007 import java.io.IOException;
00008
00009 public class Library {
00010
00011 public static String getFile(String file) throws IOException {
00012 return readFile(file);
00013 }
00014
00015 public static String getFileReplace(String keyWord,String newWord,String file) throws IOException {
00016 String texto;
00017 texto = readFile(file);
00018 texto = replaceWord(keyWord,newWord,texto);
00019 return texto;
00020 }
00021
00022 public static String replaceWord(String keyword,String newWord, String texto) {
00023 String newText;
00024 int indice;
00025 newText=new String();
00026 indice=texto.indexOf(keyword);
00027 while(indice!=-1){
00028 newText+=texto.substring(0,indice)+newWord;
00029 texto=texto.substring(indice + keyword.length());
00030 indice=texto.indexOf(keyword);
00031 }
00032 return newText+texto;
00033 }
00034
00035 public static String getFileListReplace(String[] keywords,String[] newWords,String file) throws IOException {
00036 String texto;
00037 texto = readFile(file);
00038 return getWordListReplace(keywords,newWords,texto);
00039 }
00040
00041 public static String getWordListReplace(String[] keywords,String[] newWords,String text) throws IOException {
00042 int menorTamanho=0;
00043 menorTamanho=keywords.length;
00044
00045 if(menorTamanho > newWords.length) menorTamanho = newWords.length;
00046
00047
00048 for(int i =0;i<menorTamanho;i++)
00049 text = replaceWord(keywords[i],newWords[i],text);
00050
00051 return text;
00052 }
00053
00054 public static String readFile(String file) throws IOException {
00055 String context = "";
00056 String aux = null;
00057 FileReader fr = new FileReader(file);
00058 BufferedReader bf = new BufferedReader(fr);;
00059
00060 aux=bf.readLine();
00061 while(aux!=null){
00062 aux+="\n";
00063 context+=aux;
00064 aux=bf.readLine();
00065 }
00066 fr.close();
00067 bf.close();
00068
00069 return context;
00070 }
00071
00072 }