Results 1 to 7 of 7
Thread: Txt Files
- 01-08-2011, 03:28 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 4
- Rep Power
- 0
Txt Files
Hello everyone,
I Would like to ask you 2 simple questions that I cannot answer by myself.
1 I need to "import" a txt file to memory and then print it on screen.
I have already done the first part. I is correct?
2 How can I print the file to the screen?
private static void leInfo(){
LineNumberReader ficheiro;
try {
ficheiro = new LineNumberReader(new FileReader("Uvas.txt"));
Scanner sc = new Scanner(ficheiro);
while(sc.hasNext()){
String nome =sc.next();
Regiao reg=Regiao.valueOf(sc.next());
Qualidade qual=Qualidade.valueOf(sc.next());
int quantidade=sc.nextInt();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Thank You very much
- 01-08-2011, 03:39 PM #2
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
you can use System.out.println() , System.out.print(), System.out.printf() ......2 How can I print the file to the screen?
- 01-08-2011, 04:08 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 4
- Rep Power
- 0
System.out.print("uvas.txt")
will this show on screen the content of the file?
example:
uvas.txt
content:"
(trincadeira douro boa 100)
"
- 01-08-2011, 04:15 PM #4
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
you have already done this
those variables contains the contents from the file already. All you have to do is print them outJava Code:while(sc.hasNext()){ String nome =sc.next(); Regiao reg=Regiao.valueOf(sc.next()); Qualidade qual=Qualidade.valueOf(sc.next()); int quantidade=sc.nextInt();
- 01-08-2011, 04:21 PM #5
Member
- Join Date
- Jan 2011
- Posts
- 4
- Rep Power
- 0
but in main i did
System.out.println("Uvas.txt");
and appear "Uvas.txt" not the content
- 01-08-2011, 04:28 PM #6
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
- 01-08-2011, 04:31 PM #7
Member
- Join Date
- Jan 2011
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Convert avi, mpeg, wmv media files to .flv files in java code
By vinay1497 in forum New To JavaReplies: 8Last Post: 07-30-2010, 05:47 PM -
import from dsv files and export to csv files
By 10x2 in forum New To JavaReplies: 12Last Post: 04-30-2010, 11:56 AM -
working with files (text files)
By itaipee in forum New To JavaReplies: 1Last Post: 02-24-2009, 11:38 AM -
Behaving text files like binary files
By Farzaneh in forum New To JavaReplies: 2Last Post: 08-27-2008, 03:20 PM -
Text and image files within jar files
By erhart in forum Advanced JavaReplies: 8Last Post: 01-19-2008, 04:43 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks