Well hello everyone. I am facing a problem while executing a task. My task is to make such a code which will search for my source code file (abc.java) in all directories and then displays the code in textarea inside frame and along with that i also have to display the path of the file in text field. I have coded something but i am really not getting anywhere near my task. Sincere help needed urgently.Thankx in advance.
import javax.swing.*; import java.awt.*; import java.io.*; import java.util.* public class Lab extends JFrame { static JTextField jf; static String Files; static File ff = new File("Lab.java"); static File ff1 = new File("D:\\"); public static void main(String[] args) { Lab bf = new Lab(); //Making Frame bf.setBounds(20, 20, 400, 400); bf.setLayout(new BorderLayout()); JTextField jf = new JTextField(""); TextArea jt = new TextArea(" "); Search(ff1); bf.add(jf, BorderLayout.NORTH); //Now adding the ALL panelS to frame bf.add(jt, BorderLayout.CENTER); bf.setVisible(true); } //Main Ends public static void Search(File file) { try { FileInputStream fis = new FileInputStream(file); /* if (!ff.exists()) { throw new FileNotFoundException("file doesn't exist"); }*/ File[] listOfFiles = file.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isDirectory()) { Search(listOfFiles[i]); } else if (!(listOfFiles[i].isDirectory())) { Files = listOfFiles[i].getName(); if (Files.equals("Lab.java")) { jf.setText("file found"); } } } String path = ff.getAbsolutePath(); } catch (Exception e) { } } }