Skip to content
Snippets Groups Projects
Commit 798f8cd3 authored by Pedro Pablo Cardona Arroyave's avatar Pedro Pablo Cardona Arroyave
Browse files

File Writer was added

parent 53d6d756
Branches
No related tags found
No related merge requests found
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
......@@ -326,26 +329,14 @@ class Utils{
return currentDirectoryPath + System.getProperty("file.separator") +fileName;
}
public static String[] splitText(String string, int numberOfWords){
String[] splitText = new String[numberOfWords];
StringBuilder sb = new StringBuilder();
int index = 0;
for (int i = 0; i<string.length();i++){
if(Character.isWhitespace(string.charAt(i))){
String word = sb.toString();
if(!word.isBlank()){
splitText[index]=word;
index++;
sb = new StringBuilder();
}
} else{
sb.append(string.charAt(i));
}
if(i == string.length()-1){
splitText[index] = sb.toString();
}
public void arrayToFile(int[] array, String fileName) throws IOException{
FileOutputStream out= new FileOutputStream(fileName);
FileChannel file = out.getChannel();
ByteBuffer but = file.map(FileChannel.MapMode.READ_WRITE,0, 4L * array.length);
for(int i : array){
but.putInt(i);
}
return splitText;
file.close();
}
public static String[] dividedText(String line, int number){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment