原谅我的无知我是JSF和Primeface的新手。我上传了一个Primeface文件,然后ı需要阅读。你可以看到我的代码然后我会问我的问题。
SEND.java CLASS
private UploadedFile file;
public UploadedFile getFile() {
return file;
}
public void setFile(UploadedFile file) {
this.file = file;
}
public void handleFileUpload(FileUploadEvent event) {
try {
File targetFolder = new File("C:\\Users\\Fatih\\Desktop\\DONE PNS\\pns_text");
InputStream inputStream = event.getFile().getInputstream();
OutputStream out = new FileOutputStream(new File(targetFolder,
event.getFile().getFileName()));
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
inputStream.close();
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
BUFFEREDREADERPNS.java CLASS
private BufferedReader br = null;
private String tokenString = "";
//SETTERS GETTERS
public void read(){
try {
String sCurrentLine;
br = new BufferedReader(new FileReader(??????????????));
while ((sCurrentLine = br.readLine()) != null) {
System.out.println(sCurrentLine);
tokenString = tokenString + sCurrentLine;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
send.xhtml文件
<h:form enctype="multipart/form-data">
<p:fileUpload mode="advanced"
fileUploadListener="#{send.handleFileUpload}"
allowTypes="/(\.|\/)(txt)$/"
auto="true" />
<p:growl id="messages" showDetail="true"/>
</h:form>
<p:commandButton actionListener="#{bufferedReaderPNS.read}" action="send"
value="Send" ajax="false" />
我的问题是我不知道如何处理我上传的文件。在read()方法的BUFFEREDREADERPNS.java类中我需要用问号写什么?我希望我能清楚地告诉我的问题,谢谢你的回答。