Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.Serializable;
- public class Produto implements Serializable {
- public int codigo;
- public String nome;
- public int qtd;
- public double preco;
- }
- Produto p[] =new Produto [100] ;
- public static void gravar (Produto[] p, int n){
- int i;
- File binaryFile = new File ("Produtos.dat");
- try{
- FileOutputStream fos = new FileOutputStream(binaryFile);
- ObjectOutputStream oos = new ObjectOutputStream(fos);
- // escreve todos os produtos do registro no arquivo
- for (i=0;i<n;i++){
- oos.writeObject (p[i]);
- }
- // fecha o arquivo
- oos.flush();
- oos.close();
- }
- catch(IOException e)
- {
- System.err.println(e.getMessage());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement