-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLibrary.java
More file actions
72 lines (58 loc) · 1.99 KB
/
Library.java
File metadata and controls
72 lines (58 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Classe Library - biblioteca de métodos
*/
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Library {
public static String getFile(String file) throws IOException {
return readFile(file);
}
public static String getFileReplace(String keyWord,String newWord,String file) throws IOException {
String texto;
texto = readFile(file);
texto = replaceWord(keyWord,newWord,texto);
return texto;
}
public static String replaceWord(String keyword,String newWord, String texto) {
String newText;
int indice;
newText=new String();
indice=texto.indexOf(keyword);
while(indice!=-1){
newText+=texto.substring(0,indice)+newWord;
texto=texto.substring(indice + keyword.length());
indice=texto.indexOf(keyword);
}
return newText+texto;
}
public static String getFileListReplace(String[] keywords,String[] newWords,String file) throws IOException {
String texto;
texto = readFile(file);
return getWordListReplace(keywords,newWords,texto);
}
public static String getWordListReplace(String[] keywords,String[] newWords,String text) throws IOException {
int menorTamanho=0;
menorTamanho=keywords.length;
if(menorTamanho > newWords.length) menorTamanho = newWords.length;
/*caso o sistema fique muito lento faremos uma nova funcao que substitui de uma vez só*/
for(int i =0;i<menorTamanho;i++)
text = replaceWord(keywords[i],newWords[i],text);
return text;
}
public static String readFile(String file) throws IOException {
String context = "";
String aux = null;
FileReader fr = new FileReader(file);
BufferedReader bf = new BufferedReader(fr);;
aux=bf.readLine();
while(aux!=null){
aux+="\n";
context+=aux;
aux=bf.readLine();
}
fr.close();
bf.close();
return context;
}
}