Skip to content

Commit

Permalink
create FileWork
Browse files Browse the repository at this point in the history
  • Loading branch information
boroda4436 authored and jekaGr committed Oct 2, 2024
1 parent cecd533 commit a1375f4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
</executions>
<configuration>
<configLocation>${maven.checkstyle.plugin.configLocation}</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
Expand Down
35 changes: 33 additions & 2 deletions src/main/java/core/basesyntax/FileWork.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
package core.basesyntax;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Arrays;

public class FileWork {
public String[] readFromFile(String fileName) {
//write your code here
return null;
File file = new File(fileName);
StringBuilder stringBuilder = new StringBuilder();
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
String value = bufferedReader.readLine();

while (value != null) {
String[] strings = value.split(" ");
for (String str : strings) {
String st = str.toLowerCase().replaceAll("[!?.]","");
if (st.startsWith("w")) {
stringBuilder.append(st).append(" ");
}
}

String ff = stringBuilder.toString();
value = bufferedReader.readLine();
}
} catch (Exception e) {
throw new RuntimeException("Can't read file",e);
}
if (!stringBuilder.isEmpty()) {
String[] str = stringBuilder.toString().split(" ");
Arrays.sort(str);
return str;
} else {
return new String[0];
}
}
}

0 comments on commit a1375f4

Please sign in to comment.