I need to upload and read a text file with PrimeFaces and JSF. My question is that when I uploaded the text file, where is it stored?
Here is my .xhtml
file:
<p:fileUpload value="#{send.file }" mode="simple" />
</h:form>
<p:commandButton actionListener="#{send.upload}" value="Send" ajax="false" />
And Java class:
public class Send {
private UploadedFile file;
public void upload() {
if (file != null) {
FacesMessage msg = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
I also found this example to read the file:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class BufferedReaderExample {
public static void main(String[] args) {
try (BufferedReader br = new BufferedReader(new FileReader("C:\\testing.txt")))
{
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null) {
System.out.println(sCurrentLine);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
My other question is in this example "C:\\testing.txt"
is given as a path? Which address I must give to read my uploaded file?