• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can i read data from file

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am new to I/O's.
I want to read data from file and display that data on form. If you have any sample code....
Any help would be greatly appeciate.
Ravi
 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
the following code will read a file and return the files data a line at a time. I am not sure how you want to process your data, but this part will at least show you how to open a file and access the data a String at a time. bwin.readline() returns a null when it gets to the end of the file.
You can also use just FileReader and do in.read to return a character at a time if that better suits your purpose. (I can send another bit of code showing that if you are interested.)
Hope this helps,
Kim

public void readFile() throws IOException {
File inputFile = new File("C:\\myfile.txt");
FileReader in = new FileReader(inputFile); BufferedReader bwin = new BufferedReader(in);
String line;
while ((line=bwin.readLine()) !=null){
// code here to parse line and/or do
// whatever you want with data
System.out.println(line) // this will show you what you // read in from file
}
bwin.close();
in.close();
}

Originally posted by Ravi Mandalapu:
Hi,
I am new to I/O's.
I want to read data from file and display that data on form. If you have any sample code....
Any help would be greatly appeciate.
Ravi


 
Ravi Mandalapu
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kim Kantola,
Thank you very much...
I fixed my problem...
ravi

Originally posted by Kim Kantola:
Hi,
the following code will read a file and return the files data a line at a time. I am not sure how you want to process your data, but this part will at least show you how to open a file and access the data a String at a time. bwin.readline() returns a null when it gets to the end of the file.
You can also use just FileReader and do in.read to return a character at a time if that better suits your purpose. (I can send another bit of code showing that if you are interested.)
Hope this helps,
Kim

public void readFile() throws IOException {
File inputFile = new File("C:\\myfile.txt");
FileReader in = new FileReader(inputFile); BufferedReader bwin = new BufferedReader(in);
String line;
while ((line=bwin.readLine()) !=null){
// code here to parse line and/or do
// whatever you want with data
System.out.println(line) // this will show you what you // read in from file
}
bwin.close();
in.close();
}


 
That feels good. Thanks. Here's a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic