Fórum Dividir aquivo TXT em vários arquivos TXT - Java #534458
14/10/2015
0
public static void main(String[] args) throws IOException {
InputStream is = new FileInputStream("ARQUIVO.TXT");
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String linha = br.readLine();
int numeroArquivo = 1;
while (linha != null) {
File file = new File("ARQUIVO" + numeroArquivo + ".TXT");
OutputStream os = new FileOutputStream(file);
OutputStreamWriter osw = new OutputStreamWriter(os);
BufferedWriter bw = new BufferedWriter(osw);
if (!linha.contains("P") && linha.trim().length() == 11) {
bw.append(linha);
linha = null;
} else {
bw.append(linha);
bw.newLine();
linha = br.readLine();
}
numeroArquivo++;
bw.close();
}
br.close();
//bw.close();
}
[img:descricao=Arquivo.txt]http://arquivo.devmedia.com.br/forum/imagem/458404-20151014-154415.png[/img]
Jerônimo Verçosa
Curtir tópico
+ 0Posts
15/10/2015
Jerônimo Verçosa
Gostei + 0
15/10/2015
Jothaz
Gostei + 0
15/10/2015
Jerônimo Verçosa
100001610
2P071035368
30000000004
100001611
2P071034131
30000000005
Gostei + 0
15/10/2015
Jothaz
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)