Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) throws IOException {
- //conteudo
- String conteudo = "arquivo inicialnlinha2"; //conteudo inicial
- String conteudo1 = null; //o que vai ser separado para o arquivo1(comentarios)
- String conteudo2 = null; //o que vai ser separado para o arquivo2(codigo a ser compilado)
- //cria os 3 arquivos (inicial , txt dos comentarios e txt do codigo
- File arquivo = new File("arquivo.txt");
- File arquivo1 = new File ("arquivo1.txt");
- File arquivo2 = new File("arquivo2.txt");
- //prepara pra escrever no arquivo inicial
- FileWriter fw = new FileWriter(arquivo.getAbsoluteFile());
- BufferedWriter bw = new BufferedWriter(fw);
- //escreve e fecha o arquivo
- bw.write(conteudo);
- bw.close();
- //le o arquivo linha por linha
- FileReader ler = new FileReader("arquivo.txt");
- BufferedReader reader = new BufferedReader(ler);
- String linha;
- while( (linha = reader.readLine()) != null) {
- System.out.println(linha); //printa linha por linha do arquivo inicial
- if (linha.contains("//")) { //se o arquivo conter // , ele separa para outro arquivo
- }
- else {
- }
- }
- }
Add Comment
Please, Sign In to add comment