Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tdt4100
v2022
students
Commits
cf928769
Commit
cf928769
authored
Mar 27, 2022
by
Børge Haugset
Browse files
finally
parent
af174178
Changes
1
Hide whitespace changes
Inline
Side-by-side
foreksempel/src/main/java/uke13/unntak/FilFinally.java
0 → 100644
View file @
cf928769
package
uke13.unntak
;
import
java.io.BufferedReader
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.util.ArrayList
;
public
class
FilFinally
{
private
static
void
lesFil
()
{
BufferedReader
br
=
null
;
// For å initialisere den...
try
{
int
a
=
3
/
0
;
String
filnavn
=
"C:/Users/borgeha/tdt4100-v2022/students/foreksempel/src/main/java/uke13/unntak/Linjer.txt"
;
FileReader
fr
=
new
FileReader
(
filnavn
);
br
=
new
BufferedReader
(
fr
);
int
count
=
0
;
String
linje
;
while
(
br
.
ready
())
{
linje
=
br
.
readLine
();
count
++;
System
.
out
.
println
(
"Linje nummer "
+
count
+
": "
+
linje
);
}
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"IOException: "
+
e
.
getMessage
());;
}
finally
{
System
.
out
.
println
(
"Før close"
);
try
{
if
(
br
!=
null
)
br
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
System
.
out
.
println
(
"Etter close"
);
}
}
public
static
void
main
(
String
[]
args
)
{
lesFil
();
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment