Hi,
I am using jdeveloper 11.1.1.6.0. I wanted to download a file on clicking a command button. I have a folder created in my custom project were i have the files for download.
Using the af:fileDownloadActionListener
<af:commandLink text="#{bundle['SFDOA_LIST2_DESC']}" id="commandLink1">
<af:fileDownloadActionListener filename="Tax_DoA" method="#{home.fileDownload}"/>
</af:commandLink>
public void fileDownload(FacesContext facesContext,OutputStream out) throws IOException {
File f = new File("C:\Dev\\Commercial\Sources\ADF Development Sources\Dev_DoA\DoACustom\public_html\az\doa\view\externalfiles\Tax_DoA.txt");
File newFile= new File(f.getCanonicalPath());
System.out.println(newFile.getAbsolutePath());
if (newFile.exists()) {
FileInputStream fis;
byte[] b;
try {
fis = new FileInputStream(newFile);
int n;
while ((n = fis.available()) > 0) {
b = new byte[n];
int result = fis.read(b);
out.write(b, 0, b.length);
if (result == -1)
break;
}
} catch (IOException e) {
e.printStackTrace();
}
try {
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
If i give the whole file path then the file is getting download. But when we deploy it on the server we cannot mention the whole file path.
If i mention the file path as like
File f = new File("..\\public_html\\az\\doa\\view\\externalfiles\\Tax_DoA.txt");
System.out.println(newFile.getCanonicalPath);
It is printing C:\..AppData\Roaming\JDeveloper\system11.1.1.6.38.61.92\. File is getting downloaded by there we no contents in the file.
Could some one tell me like what is the file path i have to mention.