Galera achei um metodo p ler e escrever arquivo txt, porem estou com um erro q nao consigo entender quando o metodo ler o arquivo e vai setar o dado relativo a UF no banco da pau se alguem percebe me ajuda so falta isso p terminar esse modulo.
public void lerArquivo(ActionEvent event) throws FileNotFoundException, IOException {
Vigencia v1 = vigenciaFacade.getVigencia();
if (v1 != null) {
FacesUtil.mensageWarn("", "Já exite uma vigência aberta");
} else {
teste.deletarArquivosFrequencias();
teste.deletarArquivosMecs();
if (inputFileController.getFileList().size() > 0 && validarFormulario()) {
File f = inputFileController.getCurrentFile().getFile();
List<String> lines = new ArrayList<String>();
try {
LerEscreveArquivo lea = new LerEscreveArquivo(f);
int i = 0;
String ln;
while ((ln = lea.getLine(i++)) != null) {
lines.add(ln);
}
} catch (IOException e) {
System.err.println(e);
}
List<ArquivoMec> arquivoMecs = new ArrayList<ArquivoMec>();
for (int j = 0; j < lines.size(); j++) {
String string = lines.get(j).replace("\"", "");
String[] ss = string.split(";");
ArquivoMec a = new ArquivoMec();
for (int i = 0; i < ss.length; i++) {
if (ss.length > 0 && ss[0] != null && !ss[0].equals("")) {
String str = ss[0].replace("ÿþ", "");
a.setTipoRegistro(new TipoRegistro(Integer.parseInt(str.trim())));
}
if (ss.length > 1 && ss[1] != null) {
String ano = Pattern.compile("[^0-9]").matcher(ss[1]).replaceAll("");
a.setAno(new Integer(ano.trim()));
}
if (ss.length > 2 && ss[2] != null) {
String m1 = Pattern.compile("[^0-9]").matcher(ss[2]).replaceAll("");
a.setMes1(Integer.parseInt(m1.trim()));
}
if (ss.length > 3 && ss[3] != null) {
String m2 = Pattern.compile("[^0-9]").matcher(ss[3]).replaceAll("");
a.setMes2(Integer.parseInt(m2.trim()));
}
[b]if (ss.length > 4 && ss[4] != null) {
String uf = Pattern.compile("[^0-9]").matcher(ss[4]).replaceAll("");
a.setUf(uf);
}[/b]
if (ss.length > 5 && ss[5] != null) {
String idMunicipio = Pattern.compile("[^0-9]").matcher(ss[5]).replaceAll("");
a.setMunicipio(new Municipio(Integer.parseInt(idMunicipio)));
}
if (ss.length > 6 && ss[6] != null && !ss[6].equals("")) {
String inep = Pattern.compile("[^0-9]").matcher(ss[6]).replaceAll("");
a.setEscola(new Escola(Integer.parseInt(inep)));
a.setInep(Integer.parseInt(inep));
}
if (ss.length > 7 && ss[7] != null && !ss[7].equals("")) {
String nis = Pattern.compile("[^0-9]").matcher(ss[7]).replaceAll("");
a.setNis(nis);
}
if (ss.length > 8 && ss[8] != null) {
String nome = Pattern.compile("[^A-Z, a-z]").matcher(ss[8]).replaceAll("");
a.setNome(nome);
}
if (ss.length > 9 && ss[9] != null) {
String nomeResponsavel = Pattern.compile("[^A-Z, a-z]").matcher(ss[9]).replaceAll("");
a.setNomeResponsavel(nomeResponsavel);
}
if (ss.length > 10 && ss[10] != null) {
String[] st = ss[10].split("/");
String somenteNumeros1 = Pattern.compile("[^0-9]").matcher(st[0]).replaceAll("");
String somenteNumeros2 = Pattern.compile("[^0-9]").matcher(st[1]).replaceAll("");
String somenteNumeros3 = Pattern.compile("[^0-9]").matcher(st[2]).replaceAll("");
GregorianCalendar gc = new GregorianCalendar(Integer.parseInt(somenteNumeros3), (Integer.parseInt(somenteNumeros2) - 1),
Integer.parseInt(somenteNumeros1));
a.setDataNascimento(gc.getTime());
}
if (ss.length > 11 && ss[11] != null) {
String ser = Pattern.compile("[^0-9]").matcher(ss[11]).replaceAll("");
a.setSerie(new Serie(Integer.parseInt(ser)));
}
if (ss.length > 12 && ss[12] != null) {
String idSituacao = Pattern.compile("[^0-9]").matcher(ss[12]).replaceAll("");
a.setSituacao(new Situacao(Integer.parseInt(idSituacao)));
}
if (ss.length > 13 && ss[13] != null) {
String idAcompanhamento = Pattern.compile("[^0-9]").matcher(ss[13]).replaceAll("");
a.setTipoAcompanhamento(new TipoAcompanhamento(Integer.parseInt(idAcompanhamento)));
}
if (ss.length > 14 && ss[14] != null) {
String solicitante = Pattern.compile("[^0-9]").matcher(ss[14]).replaceAll("");
a.setSolicitante(solicitante);
}
if (ss.length > 15 && ss[15] != null) {
String telefone = Pattern.compile("[^0-9]").matcher(ss[15]).replaceAll("");
a.setTelefone(telefone);
}
if (ss.length > 16 && ss[16] != null) {
String inepDestino = Pattern.compile("[^0-9]").matcher(ss[16]).replaceAll("");
a.setInepDestino(inepDestino);
}
if (ss.length > 17 && ss[17] != null) {
a.setSituacaoDestino(null);
}
if (ss.length > 18 && ss[18] != null && !ss[18].equals("")) {
a.setFrequenciaMes1(null);
}
if (ss.length > 19 && ss[19] != null && !ss[19].equals("")) {
a.setMotivoBfMes1(null);
}
if (ss.length > 20 && ss[20] != null && !ss[20].equals("")) {
a.setFrequenciaMes2(null);
}
if (ss.length > 21 && ss[21] != null && !ss[21].equals("")) {
a.setMotivoBfMes2(null);
}
}
System.out.println(string);
arquivoMecs.add(a);
}
try {
// codigos
}
}