Jump to content



Recommended Posts

import java.io.*;

import java.util.*;

public class ReadArrayFile {

public static void main(String[] args) {

String filename = "produtos.txt";

try {

FileReader f = new FileReader(filename);

BufferedReader input = new BufferedReader(f);

String str; //string de linhas do ficheiro

ArrayList<String> fa = new ArrayList<String>(); // criar arraylist fa

/* ciclo leitura ficheiro */

while ((str = input.readLine()) != null) {

fa.add(str);//adicionar linha ao arraylist


/* ciclo de output ficheiro */


System.out.println("|      a  b  c  d        |");


for (int i=0;i<fa.size();i++){

System.out.print("      ");

System.out.println(fa.get(i)+" ");//obter linha do arrylist e imprimir


input.close();//terminar o input

} catch (IOException e) {


System.out.println("ficheiro "+filename+" nao encontrado");




o print disto sai me


|      a  b  c  d        |







gostava se me pudessem ajudar a ficar cada um dos "produtos" debaixo de uma letrae so quando se colhesse e que o preço aparecia....

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.