Guest User

Untitled

a guest
Apr 20th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. public static void main(String[] args) throws IOException {
  2. //conteudo
  3. String conteudo = "arquivo inicialnlinha2"; //conteudo inicial
  4. String conteudo1 = null; //o que vai ser separado para o arquivo1(comentarios)
  5. String conteudo2 = null; //o que vai ser separado para o arquivo2(codigo a ser compilado)
  6.  
  7. //cria os 3 arquivos (inicial , txt dos comentarios e txt do codigo
  8. File arquivo = new File("arquivo.txt");
  9. File arquivo1 = new File ("arquivo1.txt");
  10. File arquivo2 = new File("arquivo2.txt");
  11.  
  12. //prepara pra escrever no arquivo inicial
  13. FileWriter fw = new FileWriter(arquivo.getAbsoluteFile());
  14. BufferedWriter bw = new BufferedWriter(fw);
  15.  
  16. //escreve e fecha o arquivo
  17. bw.write(conteudo);
  18. bw.close();
  19.  
  20. //le o arquivo linha por linha
  21. FileReader ler = new FileReader("arquivo.txt");
  22. BufferedReader reader = new BufferedReader(ler);
  23. String linha;
  24. while( (linha = reader.readLine()) != null) {
  25. System.out.println(linha); //printa linha por linha do arquivo inicial
  26. if (linha.contains("//")) { //se o arquivo conter // , ele separa para outro arquivo
  27. }
  28. else {
  29.  
  30. }
  31. }
  32.  
  33. }
Add Comment
Please, Sign In to add comment