Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within I/O and Streams
Search Coderanch
Advance search
Google search
Register / Login
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
Forum:
I/O and Streams
filenotfound Exception encountered,kindly help
neha gautam
Ranch Hand
Posts: 32
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hii .....my code for readin the file is...
import java.io.*; public class ReadFile { /** * Fetch the entire contents of a text file, and return it in a String. * This style of implementation does not throw Exceptions to the caller. * * @param aFile is a file which already exists and can be read. */ static public String getContents(File aFile) { //...checks on aFile are elided StringBuilder contents = new StringBuilder(); try { //use buffering, reading one line at a time //FileReader always assumes default encoding is OK! BufferedReader input = new BufferedReader(new FileReader(aFile)); try { String line = null; //not declared within while loop /* * readLine is a bit quirky : * it returns the content of a line MINUS the newline. * it returns null only for the END of the stream. * it returns an empty String if two newlines appear in a row. */ while (( line = input.readLine()) != null){ contents.append(line); contents.append(System.getProperty("line.separator")); } } finally { input.close(); } } catch (IOException ex){ ex.printStackTrace(); } return contents.toString(); } }
i m calling the above function in my swing.. and its givin me filenot found exception, i m not able to figure why??
please help:
callin prgm
import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.lang.System; import java.lang.String; import java.io.*; import javax.swing.BoxLayout; import javax.swing.JTextArea; import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JScrollPane; public class UI_new extends JPanel implements ActionListener { private JRadioButton[] files = null; private JScrollPane scrollPane; private JPanel radioButtonPanel; private JPanel actionPanel; private BoxLayout layout; private ButtonGroup group; private String file_name_selected; private String data; public UI_new() { radioButtonPanel = new JPanel(); layout = new BoxLayout(radioButtonPanel, BoxLayout.Y_AXIS); radioButtonPanel.setLayout(layout); group = new ButtonGroup(); updateRadioButtonPanel(); scrollPane = new JScrollPane(radioButtonPanel); scrollPane.setPreferredSize(new Dimension(400,300)); add(scrollPane, BorderLayout.CENTER); actionPanel = new JPanel(); add(actionPanel, BorderLayout.SOUTH); } public void updateRadioButtonPanel() { String[] fileNames = DirectoryTest.getFilesInDir("C:\\watri\\files"); files = new JRadioButton[fileNames.length]; for(int i = 0; i < fileNames.length; i++) { files[i] = new JRadioButton(fileNames[i]); group.add(files[i]); radioButtonPanel.add(files[i]); //Register a listener for the radio buttons. files[i].addActionListener(this); } radioButtonPanel.repaint(); } public void actionPerformed(ActionEvent e) { file_name_selected= e.getActionCommand(); data=ReadFile.getContents(new File(file_name_selected)); JTextArea a=new JTextArea(10,30); a.setText(data); } public static void main(String[] args) { JFrame f = new JFrame(); UI_new ui = new UI_new(); f.setContentPane(ui); f.pack(); f.setVisible(true); } }
thanks to all
Sagar Rohankar
Ranch Hand
Posts: 2908
1
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Print out all the files name with path, see whether the files exist on that path or not .
[LEARNING bLOG]
|
[Freelance Web Designer]
|
[and "Rohan" is part of my surname]
neha gautam
Ranch Hand
Posts: 32
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thanks sagar, ill try
Swastik Dey
Bartender
Posts: 2270
20
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
public void actionPerformed(ActionEvent e) { file_name_selected= e.getActionCommand(); data=ReadFile.getContents(new File("C:\\watri\\files\\"+file_name_selected)); //JTextArea a=new JTextArea(10,30); //a.setText(data); System.out.println(data); }
Swastik
Ulf Dittmer
Rancher
Posts: 43081
77
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Please do not post the same question multiple times. Let's continue the discussion in the
original thread
.
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Delete files in a directory
help with textarea insertion
need help with exception
AWT FlowLayout to BorderLayout
Read from file and display nonduplicate words in ascending order.
More...