当前位置: 技术问答>java相关
编译出错??
来源: 互联网 发布时间:2015-05-25
本文导语: import java.io.*; class filestream { public static void main(String args[]) { try { File inFile=new File("file1.txt"); File outFile=new File("file2.txt"); FileInputStream fis=new FileInputStream(inFile); FileOutputStream fos=new FileOutputStream(outFil...
import java.io.*;
class filestream
{
public static void main(String args[])
{
try
{
File inFile=new File("file1.txt");
File outFile=new File("file2.txt");
FileInputStream fis=new FileInputStream(inFile);
FileOutputStream fos=new FileOutputStream(outFile);
int c;
while((c=fis.read()!=-1)
fos.write(c);
fis.close();
fos.close();
}
catch(FileNotFoundException e)
{
System.out.println("FileStreamTest:"+e);
}
catch(IOException e)
{
System.err.println("FileStreamsTest:"+e);
}
}
}
报错如下:(jcreator编译的 )
--------------------Configuration: JDK version 1.3.1 --------------------
J:pkuchar6filestream.java:15: ')' expected
while((c=fis.read()!=-1)
^
J:pkuchar6filestream.java:15: incompatible types
found : int
required: boolean
while((c=fis.read()!=-1)
^
2 errors
Process completed.
class filestream
{
public static void main(String args[])
{
try
{
File inFile=new File("file1.txt");
File outFile=new File("file2.txt");
FileInputStream fis=new FileInputStream(inFile);
FileOutputStream fos=new FileOutputStream(outFile);
int c;
while((c=fis.read()!=-1)
fos.write(c);
fis.close();
fos.close();
}
catch(FileNotFoundException e)
{
System.out.println("FileStreamTest:"+e);
}
catch(IOException e)
{
System.err.println("FileStreamsTest:"+e);
}
}
}
报错如下:(jcreator编译的 )
--------------------Configuration: JDK version 1.3.1 --------------------
J:pkuchar6filestream.java:15: ')' expected
while((c=fis.read()!=-1)
^
J:pkuchar6filestream.java:15: incompatible types
found : int
required: boolean
while((c=fis.read()!=-1)
^
2 errors
Process completed.
|
好像FileOutputStream fos=new FileOutputStream(outFile, true)就可以了
boolean指示是否采用append即追加模式
boolean指示是否采用append即追加模式
|
把 while((c=fis.read()!=-1)
改为while((c=fis.read())!=-1)
改为while((c=fis.read())!=-1)
|
加括号就可以了
否则 c 是 int , fis.read()!=-1 是 boolean, 赋值类型不匹配.
否则 c 是 int , fis.read()!=-1 是 boolean, 赋值类型不匹配.