now it is my cod and work correctly just If my text consists of 2 words and the between of this word is space, it deletes space when printing, for example, if it is Hello World in original text, it writes HelloWorld This happens to all words in new text file for example in original text is
in new file write
File file = new File("oq.txt");
File files = new File("testFile1.txt");
try (Scanner sc = new Scanner(file, StandardCharsets.UTF_8.name())) {
FileWriter writer = new FileWriter(files);
while (sc.hasNextLine()) {
// System.out.println(sc.nextLine());
String myStr = sc.nextLine();
if (myStr.startsWith("<Azan") == true) {
System.out.println(myStr);
writer.write(myStr+"\n");
}
else if (myStr.startsWith("<Day>") == true) {
System.out.println(myStr);
writer.write(myStr+"\n");
}
else if (myStr.startsWith("<Date>") == true) {
System.out.println(myStr);
writer.write(myStr+"\n");
}
else if (myStr.startsWith("<morning>") == true) {
// myStr.concat(myStr+"</morning>");
// System.out.println(myStr);
System.out.println(myStr.concat("</morning>"));
writer.write(myStr.concat("</morning>")+"\n");
}
else if (myStr.startsWith("<Sunrise>") == true) {
System.out.println(myStr.concat("</Sunrise>"));
writer.write(myStr.concat("</Sunrise>")+"\n");
}
else if (myStr.startsWith("<Noon>") == true) {
System.out.println(myStr.concat("</Noon>"));
writer.write(myStr.concat("</Noon>")+"\n");
}
else if (myStr.startsWith("<sunset>") == true) {
System.out.println(myStr.concat("</sunset>"));
writer.write(myStr.concat("</sunset>")+"\n");
}
else if (myStr.startsWith("<evening>") == true) {
System.out.println(myStr.concat("</evening>"));
writer.write(myStr.concat("</evening>")+"\n");
}
else if (myStr.startsWith("<midnight>") == true) {
System.out.println(myStr.concat("</midnight>"));
writer.write(myStr.concat("</midnight>")+"\n");
}
else if (myStr.startsWith("</Azan") == true) {
System.out.println(myStr);
writer.write(myStr+"\n");
}
//Create the file
else if (file.createNewFile()) {
System.out.println("File is created!");
} else {
System.out.println("File already exists.");
}
}
writer.close();
} catch (IOException e) {
e.printStackTrace();
}