Objetivo: Escrever informações em um arquivo qualquer.
Classe: EscreverPalavras.java
import java.io.FileOutputStream;
import java.io.PrintWriter;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author HENRIQUE
*/
public class EscreverPalavras {
public void escreve(Object texto){
try {
FileOutputStream arq = new FileOutputStream("arquivo.asm");
PrintWriter tk = new PrintWriter(arq);
tk.print(texto);
tk.close();
} catch (Exception e) {
System.out.println("ERRO !"+e.getMessage());
}
}
}
Arquivo: Main.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author HENRIQUE
*/
public class Main {
public static void main(String[] args) {
EscreverPalavras es = new EscreverPalavras();
es.escreve("Wello World!");
}
}
Saída gerada no simulador: https://www.onlinegdb.com/ |
Código no simulador:
Palavras chave:
Write data and save in Java
כתוב נתונים ושמור ב-Java
ډاټا ولیکئ او په جاوا کې خوندي کړئ
Nulis data lan simpen ing Jawa
在Java中寫入數據並保存
Записать данные и сохранить на Java
Java дээр өгөгдөл бичиж хадгална
Skriv data och spara i Java
Napišite podatke i sačuvajte u Javi
Tulis data sareng simpen dina Java
Գրեք տվյալները և պահպանեք Java-ում
Запісвайце дадзеныя і захоўвайце іх у Java
Írjon adatokat és mentse el Java-ban
Nenhum comentário:
Postar um comentário