FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-code-example/CSV_Example/src/Example.java at master · cherkavi/java-code-example · GitHub
cherkavi
/
java-code-example
Public
Notifications
You must be signed in to change notification settings
Fork
4
Star
0
Code
Issues
0
Pull requests
42
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-code-example
/
CSV_Example
/
src
/
Example.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
54 lines (47 loc) · 1.49 KB
Breadcrumbs
java-code-example
/
CSV_Example
/
src
/
Example.java
Copy path
File metadata and controls
executable file
·
54 lines (47 loc) · 1.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import
com
.
csvreader
.*;
public
class
Example
{
public
static
void
main
(
String
[]
args
){
String
path_to_file
=
"c:
\\
temp.csv"
;
write
(
path_to_file
);
read
(
path_to_file
);
}
private
static
void
write
(
String
path_to_file
){
try
{
com
.
csvreader
.
CsvWriter
writer
=
new
com
.
csvreader
.
CsvWriter
(
path_to_file
);
writer
.
writeRecord
(
new
String
[]{
"hello"
,
"#from"
,
"file
\"
CSV
\"
"
});
writer
.
writeComment
(
"hello"
);
writer
.
writeRecord
(
new
String
[]{
"hello2"
,
"from2"
,
"file2
\"
CSV
\"
"
});
writer
.
flush
();
writer
.
close
();
}
catch
(
Exception
ex
){
System
.
out
.
println
(
"Error write:"
+
ex
.
getMessage
());
}
}
private
static
void
read
(
String
path_to_file
){
System
.
out
.
println
(
"READ"
);
try
{
System
.
out
.
println
(
"begin"
);
com
.
csvreader
.
CsvReader
reader
=
new
com
.
csvreader
.
CsvReader
(
path_to_file
);
/* System.out.println("read header");
reader.readHeaders();
for(int counter=0;counter<reader.getHeaderCount();counter++){
System.out.println(counter+":"+reader.getHeader(counter));
}
*/
System
.
out
.
println
(
"read data"
);
reader
.
setComment
(
'#'
);
reader
.
setUseComments
(
true
);
while
(
reader
.
readRecord
()){
for
(
int
counter
=
0
;
counter
<
reader
.
getColumnCount
();
counter
++){
System
.
out
.
print
(
reader
.
get
(
counter
));
System
.
out
.
print
(
" -|- "
);
}
System
.
out
.
println
(
""
);
}
reader
.
close
();
System
.
out
.
println
(
"end"
);
}
catch
(
Exception
ex
){
System
.
out
.
println
(
"Error in read CSV:"
+
ex
.
getMessage
());
}
}
}
Back
|
FazBrowse Home
|
New Git URL