代码:
DataOutputStream out=
new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream("C:\\Documents and Settings\\Administrator\\桌面\\test\\test.html.txt")));
out.writeUTF(s3);
out.close();
s3 为一个xml结构的文档:
<xml><head>
<meta id="p001"/>
<script/>
</head>
<body>
<label id="a001" dict="ture">
用户
</label>
<label id="a002" dict="false">
密码
</label>
</body>
</xml>
输出结果:
<xml><head>
<meta id="p001"/>
<script/>
</head>
<body>
<label id="a001" dict="ture">
用户
</label>
<label id="a002" dict="false">
密码
</label>
</body>
</xml>
多出来2个不知道是什么的东东。
DataOutputStream out=
new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream("C:\\Documents and Settings\\Administrator\\桌面\\test\\test.html.txt")));
out.writeUTF(s3);
out.close();
s3 为一个xml结构的文档:
<xml><head>
<meta id="p001"/>
<script/>
</head>
<body>
<label id="a001" dict="ture">
用户
</label>
<label id="a002" dict="false">
密码
</label>
</body>
</xml>
输出结果:
<xml><head>
<meta id="p001"/>
<script/>
</head>
<body>
<label id="a001" dict="ture">
用户
</label>
<label id="a002" dict="false">
密码
</label>
</body>
</xml>
多出来2个不知道是什么的东东。
解决方案 »
- 将java程序打包之后,双击生成的jar文件,老是出现错误提示,用eclipse打包的
- 登录验证问题
- java操作word问题,急!!!!!!!!!
- 一个简单的问题,解决一下.我刚学JAVA的.
- 重金悬赏。。。。。。。。。。。。。。。。。。。。。。。。。。。。
- 晕啊,老是遇到这样的错误,到底是为什么啊???
- String 类实现了Clonable接口????
- 谁能给一个简单的用java实现telnet的代码,无限感激~~~
- 求SDK中库的设置~~
- 如何在jbuilder 5中添加一个jdbc驱动,详细过程?
- 刚入门者的问题
- String b=new String("ABC")定义了几个String object?(在线等)
public final void writeUTF(String str)
throws IOException以与机器无关方式使用 UTF-8 修改版编码将一个字符串写入基础输出流。
首先,通过 writeShort 之类的方法将两个字节写入输出流,表示后跟的字节数。该值是实际写出的字节数,不是字符串的长度。根据此长度,使用字符的 UTF-8 修改版编码按顺序输出字符串的每个字符。如果没有抛出异常,则计数器 written 增加写入输出流的字节总数。该值至少是 2 加 str 的长度,最多是 2 加 str 的三倍长度。
指定者:
接口 DataOutput 中的 writeUTF
参数:
str - 要写入的字符串。
抛出:
IOException - 如果发生 I/O 错误。
代码如下:
BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream("C:\\Documents and Settings\\Administrator\\桌面\\test\\test.html.txt"),"UTF-8"));
out.write(s3);
out.close();
结帖给分~