Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I mention directory path in Java web-Application
    primarykey
    data
    text
    <p>I build java web Application.</p> <p>I wrote 1 function in my class with 2 argument.If you pass directory path(where <code>.txt</code> files are saved) and filetype as a arguments to that function.It returns all the filenames,which files have with specified file extension.</p> <pre><code> public List&lt;File&gt; ListOfFileNames(String directoryPath,String fileType) { //Creating Object for File class File fileObject=new File(directoryPath); //Fetching all the FileNames under given Path File[] listOfFiles=fileObject.listFiles(); //Creating another Array for saving fileNames, which are satisfying as far our requirements List&lt;File&gt; fileNames = new ArrayList&lt;File&gt;(); for (int fileIndex = 0; fileIndex &lt; listOfFiles.length; fileIndex++) { if (listOfFiles[fileIndex].isFile()) { //True condition,Array Index value is File if (listOfFiles[fileIndex].getName().endsWith(fileType)) { //System.out.println(listOfFiles[fileIndex].getName()); fileNames .add(listOfFiles[fileIndex]); } } } return fileNames; } </code></pre> <p>I tested this function in the following 2 ways.</p> <p>Case 1:</p> <p>I created folder name as <code>InputFiles</code> on my desktop and placed <code>.txt</code> files under <code>InputFiles</code> folder.</p> <p>I pass <code>directoryPath</code> and <code>.txt</code> as a arguments to my function in the following way.It's working fine.</p> <pre><code> classNameObject.Integration("C:/Documents and Settings/mahesh/Desktop/InputFiles",".txt"); </code></pre> <p>Case 2:</p> <p>Now I placed my <code>InputFiles</code> folder under <code>src</code> folder and pass <code>directoryPath</code> as a argument in the following way.it's not working.</p> <pre><code> classNameObject.Integration("/InputFiles",".txt"); </code></pre> <p>Why I am trying case 2,If I want to work on same Application in another system,everytime I don't need to change <code>directorypath</code>.</p> <p>At deployment time also <code>case 2</code> is very useful because,we don't know where will we deploy Application.so I tried <code>case 2</code> it's not working.</p> <p>It's working,when I mention absolute path.If I mention realPath it's not working.</p> <p>How can I fix this.</p> <p>can you explain clearly.</p> <p>I hope, you understand why I am trying case 2.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload