avatar
help! string format???# Java - 爪哇娇娃
l*t
1
urgent!
how to output the first 5 letters to a file from a 20-letter string?
thank you!!!
avatar
xt
2

OutputStream out = ...;
String str = ...;
byte[] b = str.getBytes();
out.write( b, 0, 5 );

【在 l**t 的大作中提到】
: urgent!
: how to output the first 5 letters to a file from a 20-letter string?
: thank you!!!

avatar
c*t
3
why not using substring?

【在 xt 的大作中提到】
:
: OutputStream out = ...;
: String str = ...;
: byte[] b = str.getBytes();
: out.write( b, 0, 5 );

avatar
m*c
4

String str20 = ...;
Writer writer = new BufferedWriter(new FileWriter(new File(...)));
write.write (str20, 0, 5); // cannot remember it should 4 or 5
writer.close();

【在 c*****t 的大作中提到】
: why not using substring?
avatar
st
5

~~~~~~~~no need to
nest one more bah.
BufferedWriter w=new BufferedWriter(new FileWriter("filename")); should work.

【在 m**c 的大作中提到】
:
: String str20 = ...;
: Writer writer = new BufferedWriter(new FileWriter(new File(...)));
: write.write (str20, 0, 5); // cannot remember it should 4 or 5
: writer.close();

avatar
c*t
6
ffdt, use
str20.substring (0, 5)

【在 m**c 的大作中提到】
:
: String str20 = ...;
: Writer writer = new BufferedWriter(new FileWriter(new File(...)));
: write.write (str20, 0, 5); // cannot remember it should 4 or 5
: writer.close();

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。