這可能非常容易解決,但我暫時停留了一段時間。我用了一個while循環來寫數據。我想將while循環中的數據寫入String。將數據寫入字符串
public void dumpPart(Part p) throws Exception {
InputStream is = p.getInputStream();
if (!(is instanceof BufferedInputStream)) {
is = new BufferedInputStream(is);
}
int c;
System.out.println("Message: ");
while ((c = is.read()) != -1) {
System.out.write(c); //I want to write this data to a String.
}
sendmail.VerstuurEmail(mpMessage, kenmerk);
}
解決:
public void dumpPart(Part p) throws Exception {
InputStream is = p.getInputStream();
if (!(is instanceof BufferedInputStream)) {
is = new BufferedInputStream(is);
}
int c;
final StringWriter sw = new StringWriter();
System.out.println("Message: ");
while ((c = is.read()) != -1) {
sw.write(c);
}
mpMessage = sw.toString();;
sendmail.VerstuurEmail(mpMessage, kenmerk);
}
感謝您的幫助。
是否要將此數據作爲字符串存儲在對象中? –
@PeterLawrey我想將數據存儲在一個String中,對不起。 – Jef