Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Objetivo desse script Java grava linhas em um arquivo informado via linha de comando até que seja digitado . para encerrar
- @autor: Reginaldo
- compilar: javac GravaLinhas.java
- executar: java nomearquivo*/
- import java.io.*;
- import java.util.Scanner;
- public class GravaLinhas{
- static File arquivo;
- static String texto;
- public static void main(String[] args){
- Scanner entrada = new Scanner(System.in);
- if(args.length < 1){
- System.out.println("Utilização: java GravaLinhas <arquivo>");
- return;
- }
- try{
- arquivo = new File(args[0]);
- FileOutputStream fos = new FileOutputStream(arquivo);
- do{
- texto = entrada.nextLine(); //lê do teclado
- if(!texto.equals("."))
- fos.write(texto.getBytes()); //grava no arquivo
- }while(!texto.equals("."));
- fos.close();
- }catch(IOException e){
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement