求助关于流写入的问题import java.io.*;
class testfilew {
public static void main (String[] args) throws Exception
{
File fe=new File("3.txt");
fe.createNewFile();
FileWriter fw=new FileWriter(fe);
int i=0;
String [] str=new String [1024];
BufferedReader in
= new BufferedReader(new InputStreamReader(System.in));
while(true)
{
str[i]=in.readLine();
// System.out.print(str[i]);
fw.write(str[i]);
i++ ;
if(i==4)
break; }
for (int x = 0; x<4; x++) {
System.out.print(str[x]);
}
fw.flush();
fw.close();
}
}上面是我写的代码,为什么加了哪行注释和不加哪行注释完全不同,加了打出的结果都是第一次输入的,不加的话就正常,希望高于指点一下,先谢谢了
class testfilew {
public static void main (String[] args) throws Exception
{
File fe=new File("3.txt");
fe.createNewFile();
FileWriter fw=new FileWriter(fe);
int i=0;
String [] str=new String [1024];
BufferedReader in
= new BufferedReader(new InputStreamReader(System.in));
while(true)
{
str[i]=in.readLine();
// System.out.print(str[i]);
fw.write(str[i]);
i++ ;
if(i==4)
break; }
for (int x = 0; x<4; x++) {
System.out.print(str[x]);
}
fw.flush();
fw.close();
}
}上面是我写的代码,为什么加了哪行注释和不加哪行注释完全不同,加了打出的结果都是第一次输入的,不加的话就正常,希望高于指点一下,先谢谢了
解决方案 »
- 谁有jdom的中文帮助文档啊,给我一份,实在没有英文也行
- 用jxl修改了excel表后,不能再次读取
- java.lang.ArrayIndexOutOfBoundsException: 1024
- 怎么合并两个byte数组?
- 又论接口,没有方法体,实现它的类的方法体可以完全不一样,这样有什么意义呢
- jquery怎么通过标签取得它的属性呢?在线等.急.....!!!!!!!!!!!!
- 类中的composition与 aggregation关系的区别
- 如何用JAVA简单地从Oracle数据库中将一个表复制到Mysql数据库中?
- validate()方法和revalidate()方法的区别??
- TreeSet中某个元素值改变之后怎样重新变成有序?
- 对象在什么情况下可以直接去调用属性,什么情况下只能调用方法来得到属性
- 请教一道选择题
package csdn_Test_20071126;
import java.io.*;
public class Testfilew { /**
* @param args
*/
public static void main(String[] args)throws Exception {
// TODO Auto-generated method stub
int i=0;
String [] str=new String [1024];
BufferedReader in
= new BufferedReader(new InputStreamReader(System.in));
while(true)
{
str[i]=in.readLine();
System.out.print(str[i]);
i++ ;
} }}
我这都能正常显示,你再调调别的问题
1、System.out.print(str[i]); 不注释 结果:
asdf //输入
asdf //fw.write(str[i])打印
fdsa
fdsa
qwer
qwer
poiuy
poiuy
asdffdsaqwerpoiuy //System.out.print(str[x]) 打印2、注释掉 打印结果
asdf
fdsa
qwer
poiuy//上面是输入
asdffdsaqwerpoiuy //System.out.print(str[x]) 打印
这是我加了注释的结果
--------------------配置: wan - jsdk < - <默认> --------------------
as
df
fg
hj
asasasas
处理已完成。这是没加注释的结果
--------------------配置: wan - jsdk < - <默认> --------------------
as
asdf
dffg
fghj
hjasdffghj
处理已完成。不解中~~~~~~~~~~~~~~~~
猜测你的文件应是正确的,而上面所贴的内容是打印在终端上的内容吧?
估计你所用的标准输入输出是同一个终端,则可以这样解释你没加注释时的打印:
as //你输入的as
asdf //as是System.out.print(str[i])打印出的,df是你输入的
dffg //df是System.out.print(str[i])打印的,....以此类推,你输入的内容总是在回车后被打印到终端
fghj
hjasdffghj