Estou tentando realizar leitura de dados pelo teclado, com saída em um arquivo txt, mas o mesmo está retornando em branco. Qual o problema nesse trecho?
Quem puder ajudar, fico grata.
InputStream is = System.in;
InputStreamReader fis = new InputStreamReader(is);
BufferedReader br = new BufferedReader(fis);
OutputStream os = new FileOutputStream("saida.txt");
OutputStreamWriter osw = new OutputStreamWriter(os);
BufferedWriter bw = new BufferedWriter(osw);
String s = br.readLine();
while(s!=null){
bw.write(s);
bw.newLine();
s = br.readLine();
}
br.close();
bw.close();
para fazer a entrada digitada pelo teclado importe o pacote
import java.io.Console //este pacote faz a leitura do console(Prompt)
import java.io.IOException;
public class leituraTeclado{
public static void main (String args[]) throws IOException {
Console c = System.console();
if (c == null) {
//Aqui coleque a sua implementação
}
}
}
public static void main(String[] args) throws FileNotFoundException {
Scanner s = new Scanner(System.in);
PrintStream ps = new PrintStream("arquivo.txt");
while (s.hasNextLine()) {
ps.println(s.nextLine());
}
}