private static String svgToString(String fileUrl) {
String path = "D:\\1.svg";
String content = null;
try (Stream<String> lines = Files.lines(Paths.get(path))) {
content = lines.collect(Collectors.joining(System.lineSeparator()));
}catch (IOException e) {
e.printStackTrace();
}
return content;
}
private static String updateSvgFile(String svgString,String updateContent) {
String topSuffix="<text id=\"id7\" font-family=\"Avenir-Black, Avenir\" font-size=\"80\" font-weight=\"700\" fill=\"#FFFFFF\">";
String[] split = svgString.split(topSuffix);
String top = split[0] + topSuffix;
String[] splitOne = split[1].split("</text>");
String end = "</text>" + splitOne[1];
System.out.println(end);
String content =top + " <tspan x=\"200\" y=\"580\">"+updateContent+"</tspan>"+ end;
return content;
}
private static void stringToSvg(String str,String fileUrl) throws IOException {
BufferedReader bufferedReader = null;
BufferedWriter bufferedWriter = null;
try{
bufferedReader = new BufferedReader(new StringReader(str));
bufferedWriter = new BufferedWriter(new FileWriter(fileUrl));
char buf[] = new char[1024];
int len;
while ((len = bufferedReader.read(buf)) != -1) {
bufferedWriter.write(buf, 0, len);
}
}catch (IOException e){
e.printStackTrace();
}finally {
bufferedWriter.flush();
bufferedReader.close();
bufferedWriter.close();
}
}