Ola pessoal, estou com o seguinte problema.
Estou tentando retirar algumas linhas de um arquivo e regrava-lo com o mesmo nome, ou seja, vou gravar por cima das informações de um próprio arquivo algumas linhas pré-selecionadas.
O arquivo copiado deve ficar com a mesma formatação do arquivo original. Estou utilizando o ArrayList conforme sugestões. O código abaixo já está funcionando em partes, ou seja, já estou conseguindo deixar apenas as linhas que necessito, porém não está na formatação adequada: veja parte do código abaixo:
while((lin=br.readLine()) != null)
{
if (lin.length() > 8)
{
String comp= lin.substring(1, 8);
out.println(comp);
if (comp.equals("SMaplet"))
i++;
else
{
l++;
linhaTexto.add(lin);
}
}
else
linhaTexto.add(lin);
}
out.println(linhaTexto);
BufferedWriter mapModified= new BufferedWriter(new FileWriter(nomeArq));
//for(c=0;c <=l;c++)
mapModified.write("'" + linhaTexto "'");
mapModified.write("Modificado");
br.close();
mapModified.close();
linhaTexto.clear();
}
abaixo está o arquivo original, o qual deve ser filtrado e capturado algumas linhas que por sinal, aquelas linhas diferentes de Smaplet. A filtragem está ocorrendo de forma correta
IME-Version: 1.0
Content-Type: multipart/mixed; boundary=KSIDeLiMiTER
–KSIDeLiMiTER
Content-Type: application/x-CMap; version=0.1
39
;
“Node”,“RectangleShape”,12,“jKSImapplet”,7 159 75 18,-3800,-3800,-1000000,1,0,12
“Node”,“RectangleShape”,7,“NPSmartIdeas”,319 159 90 18,-3800,-3800,-1000000,1,0,12
“Node”,“RectangleShape”,6,“Mediator 0”,344 82 66 18,-1,-1000000,-1000000,1,0,12
“Node”,“EllipseShape”,4,“CMap”,182 82 55 19,-3800,-3800,-1000000,1,0,12
“Node”,“RectangleShape”,9,“KWrite”,278 82 52 18,-1,-1000000,-1000000,1,0,12
“Node”,“RectangleShape”,13,“jKSImapplet Navigator”,5 197 79 34,-3800,-3800,-1000000,1,0,12
“Node”,“RectangleShape”,18,“NPConstraintGraphs”,186 198 125 18,-3800,-3800,-1000000,1,0,12
“Node”,“RectangleShape”,3,“ConstraintGraphs”,195 159 106 18,-1,-1000000,-1000000,1,0,12
“Node”,“RectangleShape”,11,“NPKSIMapper”,96 159 83 18,-3800,-3800,-1000000,1,0,12
“Node”,“EllipseShape”,2,“jCMap”,96 82 57 19,-3800,-3800,-1000000,1,0,12
“Node”,“RectangleShape”,10,“jKSImapper”,42 120 75 18,-1,-1000000,-1000000,1,0,12
“Node”,“RectangleShape”,14,“KSImapper”,151 120 72 18,-1,-1000000,-1000000,1,0,12
“Node”,“RectangleShape”,17,“Smart Ideas”,252 120 77 18,-1,-1000000,-1000000,1,0,12
“Node”,“RectangleShape”,8,“Mediator 1”,344 121 66 18,-1,-1000000,-1000000,1,0,12
“Node”,“RectangleShape”,16,“Accord”,202 43 53 18,-1,-1000000,-1000000,1,0,12
“Node”,“RectangleShape”,15,“KMap”,311 43 51 18,-1,-1000000,-1000000,1,0,12
“SMaplet”,“LabeledConnector”,20,"",44 181,2,0,13,1,12,1,-1000000,-1000000,-1000000,0,0,12
“SMaplet”,“LabeledConnector”,21,"",69 143,2,0,12,1,10,1,-1000000,-1000000,-1000000,0,0,12
“SMaplet”,“LabeledConnector”,22,"",108 98,2,0,10,1,2,1,-1000000,-1000000,-1000000,0,0,12
“SMaplet”,“LabeledConnector”,23,"",377 105,2,0,8,1,6,1,-1000000,-1000000,-1000000,0,0,12
“SMaplet”,“LabeledConnector”,24,"",299 144,2,0,7,1,17,1,-1000000,-1000000,-1000000,0,0,12
“SMaplet”,“LabeledConnector”,25,"",221 106,2,0,17,1,4,1,-1000000,-1000000,-1000000,0,0,12
“SMaplet”,“LabeledConnector”,26,"",248 186,2,0,18,1,3,1,-1000000,-1000000,-1000000,0,0,12
“SMaplet”,“LabeledConnector”,27,"",197 135,2,0,3,1,14,1,-1000000,-1000000,-1000000,0,0,12
“SMaplet”,“LabeledConnector”,28,"",166 146,2,0,11,1,14,1,-1000000,-1000000,-1000000,0,0,12
“SMaplet”,“LabeledConnector”,33,"",170 91,2,0,2,1,4,1,-1000000,-1000000,-1000000,0,0,12
“SMaplet”,“LabeledConnector”,32,"",202 107,2,0,14,1,4,1,-1000000,-1000000,-1000000,0,0,12
“SMaplet”,“LabeledConnector”,29,"",209 90,2,0,4,1,16,1,-1000000,-1000000,-1000000,0,0,12
“SMaplet”,“LabeledConnector”,30,"",328 66,2,0,9,1,15,1,-1000000,-1000000,-1000000,0,0,12
“SMaplet”,“LabeledConnector”,31,"",349 68,2,0,6,1,15,1,-1000000,-1000000,-1000000,0,0,12
“SMaplet”,“LabeledConnector”,35,"",273 30,2,0,16,1,1,1,-1000000,-1000000,-1000000,0,0,12
“SMaplet”,“LabeledConnector”,34,"",289 27,2,0,15,1,1,1,-1000000,-1000000,-1000000,0,0,12
“Node”,“RectangleShape”,1,“KDraw”,255 5 58 18,-100,-1000000,-1000000,1,0,12
;
–KSIDeLiMiTER–
Depois que o código é executado, o arquivo fica desta maneira.
'[MIME-Version: 1.0, Content-Type: multipart/mixed; boundary=KSIDeLiMiTER, , –KSIDeLiMiTER, Content-Type: application/x-CMap; version=0.1, , 39, ;, “Node”,“RectangleShape”,12,“jKSImapplet”,7 159 75 18,-3800,-3800,-1000000,1,0,12, “Node”,“RectangleShape”,7,“NPSmartIdeas”,319 159 90 18,-3800,-3800,-1000000,1,0,12, “Node”,“RectangleShape”,6,“Mediator 0”,344 82 66 18,-1,-1000000,-1000000,1,0,12, “Node”,“EllipseShape”,4,“CMap”,182 82 55 19,-3800,-3800,-1000000,1,0,12, “Node”,“RectangleShape”,9,“KWrite”,278 82 52 18,-1,-1000000,-1000000,1,0,12, “Node”,“RectangleShape”,13,“jKSImapplet Navigator”,5 197 79 34,-3800,-3800,-1000000,1,0,12, “Node”,“RectangleShape”,18,“NPConstraintGraphs”,186 198 125 18,-3800,-3800,-1000000,1,0,12, “Node”,“RectangleShape”,3,“ConstraintGraphs”,195 159 106 18,-1,-1000000,-1000000,1,0,12, “Node”,“RectangleShape”,11,“NPKSIMapper”,96 159 83 18,-3800,-3800,-1000000,1,0,12, “Node”,“EllipseShape”,2,“jCMap”,96 82 57 19,-3800,-3800,-1000000,1,0,12, “Node”,“RectangleShape”,10,“jKSImapper”,42 120 75 18,-1,-1000000,-1000000,1,0,12, “Node”,“RectangleShape”,14,“KSImapper”,151 120 72 18,-1,-1000000,-1000000,1,0,12, “Node”,“RectangleShape”,17,“Smart Ideas”,252 120 77 18,-1,-1000000,-1000000,1,0,12, “Node”,“RectangleShape”,8,“Mediator 1”,344 121 66 18,-1,-1000000,-1000000,1,0,12, “Node”,“RectangleShape”,16,“Accord”,202 43 53 18,-1,-1000000,-1000000,1,0,12, “Node”,“RectangleShape”,15,“KMap”,311 43 51 18,-1,-1000000,-1000000,1,0,12, “Node”,“RectangleShape”,1,“KDraw”,255 5 58 18,-100,-1000000,-1000000,1,0,12, ;, , –KSIDeLiMiTER–]’
Ou seja, foi realizado um filtro de forma que consegui capturar as linhas que são necessárias, no entanto, a formatação não ficou legal.
- Percebam que o arquivo é iniciado e finalizado com apostrofe e colchete “ ‘[ “ devido a linha de comando mapModified.write("’" + linhaTexto “’”);
- Para delimitar final de linha no arquivo aparece a virgula depois do numero 12, ultimo numero de cada linha, no entanto no arquivo original não tem virgula
- Preciso que as linhas em branco sejam copiadas para o arquivo filtrado, porém isso não acontece.
O arquivo deveria ficar da seguinte maneira.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=KSIDeLiMiTER
–KSIDeLiMiTER
Content-Type: application/x-CMap; version=0.1
39
;
“Node”,“RectangleShape”,12,“jKSImapplet”,7 159 75 18,-3800,-3800,-1000000,1,0,12
“Node”,“RectangleShape”,7,“NPSmartIdeas”,319 159 90 18,-3800,-3800,-1000000,1,0,12
“Node”,“RectangleShape”,6,“Mediator 0”,344 82 66 18,-1,-1000000,-1000000,1,0,12
“Node”,“EllipseShape”,4,“CMap”,182 82 55 19,-3800,-3800,-1000000,1,0,12
“Node”,“RectangleShape”,9,“KWrite”,278 82 52 18,-1,-1000000,-1000000,1,0,12
“Node”,“RectangleShape”,13,“jKSImapplet Navigator”,5 197 79 34,-3800,-3800,-1000000,1,0,12
“Node”,“RectangleShape”,18,“NPConstraintGraphs”,186 198 125 18,-3800,-3800,-1000000,1,0,12
“Node”,“RectangleShape”,3,“ConstraintGraphs”,195 159 106 18,-1,-1000000,-1000000,1,0,12
“Node”,“RectangleShape”,11,“NPKSIMapper”,96 159 83 18,-3800,-3800,-1000000,1,0,12
“Node”,“EllipseShape”,2,“jCMap”,96 82 57 19,-3800,-3800,-1000000,1,0,12
“Node”,“RectangleShape”,10,“jKSImapper”,42 120 75 18,-1,-1000000,-1000000,1,0,12
“Node”,“RectangleShape”,14,“KSImapper”,151 120 72 18,-1,-1000000,-1000000,1,0,12
“Node”,“RectangleShape”,17,“Smart Ideas”,252 120 77 18,-1,-1000000,-1000000,1,0,12
“Node”,“RectangleShape”,8,“Mediator 1”,344 121 66 18,-1,-1000000,-1000000,1,0,12
“Node”,“RectangleShape”,16,“Accord”,202 43 53 18,-1,-1000000,-1000000,1,0,12
“Node”,“RectangleShape”,15,“KMap”,311 43 51 18,-1,-1000000,-1000000,1,0,12
“Node”,“RectangleShape”,1,“KDraw”,255 5 58 18,-100,-1000000,-1000000,1,0,12
;
–KSIDeLiMiTER–
Para ficar desta maneira tenho que desenvolver algum código ou há como resolver este problema com métodos ou propriedades do ArrayList.