Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Ø
øving 9
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Awesome group
øving 9
Commits
798f8cd3
Commit
798f8cd3
authored
2 years ago
by
Pedro Pablo Cardona Arroyave
Browse files
Options
Downloads
Patches
Plain Diff
File Writer was added
parent
53d6d756
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Task9.java
+11
-20
11 additions, 20 deletions
src/Task9.java
with
11 additions
and
20 deletions
src/Task9.java
+
11
−
20
View file @
798f8cd3
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
){
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment