cd anyone help me
i need to find a pattern in a file and replace it with new value
the pattern is a double
i need to find a pattern in a file and replace it with new value
the pattern is a double
private void write_to_file(String wplata_wyplata){
try{
BufferedReader in = new BufferedReader(new FileReader(filename));
String wczytane_dane="";
String line = in.readLine();
double sd= sr_dost;
Double a1 = new Double(sd);
while((line = in.readLine()) != null) {
wczytane_dane+=line;
line = in.readLine();
}
String patternStr = "[0-9]{0,2}\\.{0,1}[0-9]{0,2}";
String replacementStr = a1.toString();;
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(wczytane_dane);
String output = matcher.replaceAll(replacementStr);
FileWriter fstream = new FileWriter("konta//"+NumerKonta+".txt");
BufferedWriter out = new BufferedWriter(fstream);
// write wczytane_dane to a file will be here
out.close();
in.close();
}catch (FileNotFoundException e) {
System.err.println("Nie ma takiego konta(File not found!)");
}catch (IOException e) {
System.err.println(e);
} catch (NumberFormatException e) {
System.out.println("NumberFormatException: " + e.getMessage());
}catch (Exception ex) {
ex.printStackTrace(); }
}
private void write_to_file(String wplata_wyplata){
try{
BufferedReader in = new BufferedReader(new FileReader(filename));
String wczytane_dane="";
String line = in.readLine();
double sd= sr_dost;
Double a1 = new Double(sd);
while((line = in.readLine()) != null) {
wczytane_dane+=line;
line = in.readLine();
}
String patternStr = "[0-9]{0,2}\\.{0,1}[0-9]{0,2}";
String replacementStr = a1.toString();;
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(wczytane_dane);
String output = matcher.replaceAll(replacementStr);
FileWriter fstream = new FileWriter("konta//"+NumerKonta+".txt");
BufferedWriter out = new BufferedWriter(fstream);
// write wczytane_dane to a file will be here
out.close();
in.close();
}catch (FileNotFoundException e) {
System.err.println("Nie ma takiego konta(File not found!)");
}catch (IOException e) {
System.err.println(e);
} catch (NumberFormatException e) {
System.out.println("NumberFormatException: " + e.getMessage());
}catch (Exception ex) {
ex.printStackTrace(); }
}
Comment