Advertisement
Guest User

Untitled

a guest
Jul 15th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import java.io.Serializable;
  2. public class Produto implements Serializable {
  3. public int codigo;
  4. public String nome;
  5. public int qtd;
  6. public double preco;
  7. }
  8.  
  9. Produto p[] =new Produto [100] ;
  10.  
  11. public static void gravar (Produto[] p, int n){
  12. int i;
  13. File binaryFile = new File ("Produtos.dat");
  14. try{
  15. FileOutputStream fos = new FileOutputStream(binaryFile);
  16. ObjectOutputStream oos = new ObjectOutputStream(fos);
  17. // escreve todos os produtos do registro no arquivo
  18. for (i=0;i<n;i++){
  19. oos.writeObject (p[i]);
  20. }
  21. // fecha o arquivo
  22. oos.flush();
  23. oos.close();
  24. }
  25. catch(IOException e)
  26. {
  27. System.err.println(e.getMessage());
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement