import java.io.*;
public class File3
{
public static void main(String[] args) throws IOException
{
char ch;
File file1=new File("E:\\JAVA\\JICHU_JAVA\\文件操作\\newFile.txt");
try{
FileInputStream fin=new FileInputStream(file1);
System.out.println("文件中的信息为:");
ch=(char) System.in.read();
while (ch !=-1)
{
System.out.print((char)ch);
ch=fin.read();
}
fin.close();
}
catch (FileNotFoundException e)
{
System.out.println(e);
}
}
}此程序编译时提示的错为
--------------------Configuration: <Default>--------------------
E:\JAVA\JICHU_JAVA\文件操作\File3.java:15: possible loss of precision
found : int
required: char
ch=fin.read();
^
1 errorProcess completed.该如何修改,请指教!
public class File3
{
public static void main(String[] args) throws IOException
{
char ch;
File file1=new File("E:\\JAVA\\JICHU_JAVA\\文件操作\\newFile.txt");
try{
FileInputStream fin=new FileInputStream(file1);
System.out.println("文件中的信息为:");
ch=(char) System.in.read();
while (ch !=-1)
{
System.out.print((char)ch);
ch=fin.read();
}
fin.close();
}
catch (FileNotFoundException e)
{
System.out.println(e);
}
}
}此程序编译时提示的错为
--------------------Configuration: <Default>--------------------
E:\JAVA\JICHU_JAVA\文件操作\File3.java:15: possible loss of precision
found : int
required: char
ch=fin.read();
^
1 errorProcess completed.该如何修改,请指教!
System.out.println((char)ch);
赶快揭帖.....................
newFile.txt中的信息!
{
System.out.print((char)ch);
}
改成ch=fin.read();
所以将ch定义为int类型
netsummer123
调通了,可惜
只能读取,在记事本中的int型字符
import java.io.*;
public class File3
{
public static void main(String[] args) throws IOException
{
int ch;
File file1=new File("D:\\JAVA\\newFile.txt");
try{
FileInputStream fin=new FileInputStream(file1);
System.out.println("文件中的信息为:");
ch= fin.read();
while (ch!=-1)
{
System.out.print((char)ch);
ch=fin.read();
}
fin.close();
}
catch (FileNotFoundException e)
{
System.out.println(e);
}
}
}
import java.io.*;public class F
{
public static void main(String[] args) throws IOException
{
int ch;
File file1=new File("F:\\enjoy\\bean.jsp");//
try{
FileReader in=new FileReader(file1);//FileInputStream fin=new FileInputStream(file1);
BufferedReader bufferin=new BufferedReader(in);
System.out.println("文件中信息为:"); //ch= fin.read();
String str=null; while((str=bufferin.readLine())!=null)//while (ch!=-1)
{
System.out.println(str);
}
//fin.close();
in.close();
}
catch (FileNotFoundException e){
System.out.println(e);
}
catch(IOException e){System.out.println(e);} }
}
public class File3
{
public static void main(String[] args) throws IOException
{
int ch;
byte[] b = new byte[256];
File file1=new File("F:\\JavaPro\\newFile.txt");
try{
FileInputStream fin=new FileInputStream(file1);
System.out.println("文件中的信息为:");
ch= fin.read(b);
while (ch!=-1)
{
String content= new String(b);
System.out.print(content);
ch=fin.read();
}
fin.close();
}
catch (FileNotFoundException e)
{
System.out.println(e);
}
}
}
呵呵,我这就揭贴,感觉给您10分是有些少啊!
昨天没来得及看您的回复,不好意思啦!感谢大家对此帖的支持!