1
注釈付きファイルをコピーして、新しいコピー内のそれらの注釈を置き換えたいとします。しかし、私は交換を行う方法に苦労しています。私は現在の文字列にファイル全体を読み込み、新しいファイルに文字列を保存する前に注釈を交換しています:ファイル内の特定の式を置換するJava
String file = null;
void openAnnotatedSource(String path){
byte[] encoded = null;
try {
encoded = Files.readAllBytes(Paths.get(anotatedpath + "/" + path));
} catch(Exception e) {
System.out.println("Error opening annotated source.");
}
file = new String(encoded, StandardCharsets.UTF_8);
}
void replaceAnotation(String anotation, String config){
file = file.replace(anotation, config);
}
void replaceAnotation(String anotation, int config){
file = file.replace(anotation, String.valueOf(config));
}
void createFinalSource(String path){
try{
Files.write(Paths.get(targetpath + "/" + path), file.getBytes());
} catch(Exception e) {
System.out.println("Couldnt create " + targetpath + "/" + path);
}
}
私はファイルを持っ全体の時間理由としてこれを正しくやっている場合、私は知りません文字列が私にとって正しいとは思わない。