FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-code-example/DbfReader/src/TestReader.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
/
DbfReader
/
src
/
TestReader.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
230 lines (220 loc) · 5.59 KB
Breadcrumbs
java-code-example
/
DbfReader
/
src
/
TestReader.java
Copy path
File metadata and controls
executable file
·
230 lines (220 loc) · 5.59 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import
java
.
io
.
FileInputStream
;
import
com
.
linuxense
.
javadbf
.
DBFField
;
import
com
.
linuxense
.
javadbf
.
DBFReader
;
public
class
TestReader
{
public
static
void
main
(
String
[]
args
){
String
pathToDbf
=
"C:
\\
vidd2.dbf"
;
readHeaderDbfFile
(
pathToDbf
);
readDateDbfFile
(
pathToDbf
);
//printAviableCharset();
}
/** ïðî÷åñèòü è âûâåñòè íà êîíñîëü ñîäåðæèìîå DBF ôàéëà */
private
static
void
readHeaderDbfFile
(
String
pathToFile
){
try
{
DBFReader
reader
=
new
DBFReader
(
new
FileInputStream
(
pathToFile
));
// get the field count if you want for some reasons like the following
int
numberOfFields
=
reader
.
getFieldCount
();
// use this count to fetch all field information
// if required
for
(
int
i
=
0
;
i
<
numberOfFields
;
i
++) {
DBFField
field
=
reader
.
getField
(
i
);
// do something with it if you want
// refer the JavaDoc API reference for more details
System
.
out
.
print
(
"Name:"
+
field
.
getName
());
System
.
out
.
println
(
" Type:"
+
field
.
getDataType
());
}
}
catch
(
Exception
ex
){
System
.
out
.
println
(
"readFromDbfFile: "
+
ex
.
getMessage
());
}
}
/** ïðî÷åñòü è âûâåñòè íà êîíñîëü ñîäåðæèìîå DBF ôàéëà */
private
static
void
readDateDbfFile
(
String
pathToFile
){
try
{
DBFReader
reader
=
new
DBFReader
(
new
FileInputStream
(
pathToFile
));
Object
[]
record
;
while
((
record
=
reader
.
nextRecord
())!=
null
){
for
(
int
counter
=
0
;
counter
<
record
.
length
;
counter
++){
if
(
record
[
counter
]
instanceof
String
){
//System.out.print(record[counter]+" "+convertDosString((String)record[counter]));
System
.
out
.
print
(
convertDosString
((
String
)
record
[
counter
]));
}
else
{
System
.
out
.
print
(
record
[
counter
]+
" "
);
}
}
System
.
out
.
println
();
}
}
catch
(
Exception
ex
){
System
.
out
.
println
(
"readFromDbfFile: "
+
ex
.
getMessage
());
}
}
/** ïðåîáðàçîâàíèå ïðî÷èòàííûõ äàííûõ èç DBF â "íîðìàëüíîå" ïðåäñòàâëåíèå ðóññêèõ áóêâ */
private
static
String
convertDosString
(
String
value
){
StringBuffer
returnValue
=
new
StringBuffer
();
for
(
int
counter
=
0
;
counter
<
value
.
length
();
counter
++){
returnValue
.
append
(
getCharFromInteger
(
Integer
.
valueOf
(
value
.
charAt
(
counter
)),
value
.
charAt
(
counter
)));
}
return
returnValue
.
toString
();
}
/** ïðåîáðàçîâàíèå ðóññêèõ ñèìâîëîâ â "íîðìàëüíîå îòîáðàæåíèå "*/
private
static
char
getCharFromInteger
(
int
value
,
char
defaultValue
){
if
(
value
==(
128
))
return
'À'
;
if
(
value
==(
129
))
return
'Á'
;
if
(
value
==(
130
))
return
'Â'
;
if
(
value
==(
131
))
return
'Ã'
;
if
(
value
==(
132
))
return
'Ä'
;
if
(
value
==(
133
))
return
'Å'
;
if
(
value
==(
134
))
return
'Æ'
;
if
(
value
==(
135
))
return
'Ç'
;
if
(
value
==(
136
))
return
'È'
;
if
(
value
==(
137
))
return
'É'
;
if
(
value
==(
138
))
return
'Ê'
;
if
(
value
==(
139
))
return
'Ë'
;
if
(
value
==(
140
))
return
'Ì'
;
if
(
value
==(
141
))
return
'Í'
;
if
(
value
==(
142
))
return
'Î'
;
if
(
value
==(
143
))
return
'Ï'
;
if
(
value
==(
144
))
return
'Ð'
;
if
(
value
==(
145
))
return
'Ñ'
;
if
(
value
==(
146
))
return
'Ò'
;
if
(
value
==(
147
))
return
'Ó'
;
if
(
value
==(
148
))
return
'Ô'
;
if
(
value
==(
149
))
return
'Õ'
;
if
(
value
==(
150
))
return
'Ö'
;
if
(
value
==(
151
))
return
'×'
;
if
(
value
==(
152
))
return
'Ø'
;
if
(
value
==(
153
))
return
'Ù'
;
if
(
value
==(
154
))
return
'Ú'
;
if
(
value
==(
155
))
return
'Û'
;
if
(
value
==(
156
))
return
'Ü'
;
if
(
value
==(
157
))
return
'Ý'
;
if
(
value
==(
158
))
return
'Þ'
;
if
(
value
==(
159
))
return
'ß'
;
if
(
value
==(
160
))
return
'à'
;
if
(
value
==(
161
))
return
'á'
;
if
(
value
==(
162
))
return
'â'
;
if
(
value
==(
163
))
return
'ã'
;
if
(
value
==(
164
))
return
'ä'
;
if
(
value
==(
165
))
return
'å'
;
if
(
value
==(
166
))
return
'æ'
;
if
(
value
==(
167
))
return
'ç'
;
if
(
value
==(
168
))
return
'è'
;
if
(
value
==(
169
))
return
'é'
;
if
(
value
==(
170
))
return
'ê'
;
if
(
value
==(
171
))
return
'ë'
;
if
(
value
==(
172
))
return
'ì'
;
if
(
value
==(
173
))
return
'í'
;
if
(
value
==(
174
))
return
'î'
;
if
(
value
==(
175
))
return
'ï'
;
if
(
value
==(
224
))
return
'ð'
;
if
(
value
==(
225
))
return
'ñ'
;
if
(
value
==(
226
))
return
'ò'
;
if
(
value
==(
227
))
return
'ó'
;
if
(
value
==(
228
))
return
'ô'
;
if
(
value
==(
229
))
return
'õ'
;
if
(
value
==(
230
))
return
'ö'
;
if
(
value
==(
231
))
return
'÷'
;
if
(
value
==(
232
))
return
'ø'
;
if
(
value
==(
233
))
return
'ù'
;
if
(
value
==(
234
))
return
'ú'
;
if
(
value
==(
235
))
return
'û'
;
if
(
value
==(
236
))
return
'ü'
;
if
(
value
==(
237
))
return
'ý'
;
if
(
value
==(
238
))
return
'þ'
;
if
(
value
==(
239
))
return
'ÿ'
;
//if(value==())return '¥';
if
(
value
==(
240
))
return
'¨'
;
if
(
value
==(
242
))
return
'ª'
;
if
(
value
==(
244
))
return
'¯'
;
//if(value==())return '²';
//if(value==())return '³';
//if(value==())return '´';
if
(
value
==(
241
))
return
'¸'
;
if
(
value
==(
252
))
return
'¹'
;
if
(
value
==(
243
))
return
'º'
;
//if(value==())return '¼';
//if(value==())return '½';
//if(value==())return '¾';
if
(
value
==(
245
))
return
'¿'
;
return
defaultValue
;
}
}
/*
À ; 128 ;
Á ; 129 ;
 ; 130 ;
à ; 131 ;
Ä ; 132 ;
Å ; 133 ;
Æ ; 134 ;
Ç ; 135 ;
È ; 136 ;
É ; 137 ;
Ê ; 138 ;
Ë ; 139 ;
Ì ; 140 ;
Í ; 141 ;
Î ; 142 ;
Ï ; 143 ;
Ð ; 144 ;
Ñ ; 145 ;
Ò ; 146 ;
Ó ; 147 ;
Ô ; 148 ;
Õ ; 149 ;
Ö ; 150 ;
× ; 151 ;
Ø ; 152 ;
Ù ; 153 ;
Ú ; 154 ;
Û ; 155 ;
Ü ; 156 ;
Ý ; 157 ;
Þ ; 158 ;
ß ; 159 ;
à ; 160 ;
á ; 161 ;
â ; 162 ;
ã ; 163 ;
ä ; 164 ;
å ; 165 ;
æ ; 166 ;
ç ; 167 ;
è ; 168 ;
é ; 169 ;
ê ; 170 ;
ë ; 171 ;
ì ; 172 ;
í ; 173 ;
î ; 174 ;
ï ; 175 ;
ð ; 224 ;
ñ ; 225 ;
ò ; 226 ;
ó ; 227 ;
ô ; 228 ;
õ ; 229 ;
ö ; 230 ;
÷ ; 231 ;
ø ; 232 ;
ù ; 233 ;
ú ; 234 ;
û ; 235 ;
ü ; 236 ;
ý ; 237 ;
þ ; 238 ;
ÿ ; 239 ;
¥ ; ;
¨ ; 240 ;
ª ; 242 ;
¯ ; 244 ;
² ; ;
³ ; ;
´ ; ;
¸ ; 241 ;
¹ ; 252 ;
º ; 243 ;
¼ ; ;
½ ; ;
¾ ; ;
¿ ; 245 ;
*/
Back
|
FazBrowse Home
|
New Git URL