这可能很容易解决,但我现在坚持了一段时间。我有一个用于写入数据的 while 循环。我想将 while 循环中的数据写入字符串。
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);
}
谢谢你的帮助。