程序代码如下(读取文件):
import java.io.*;
public class wan3{
public static void main (String args[])throws IOException
{
File f=new File ("D:\\wan.txt");
FileInputStream du=new FileInputStream (f);
int c=du.read();
while (c!=-1){
System.out.print((char)c);
c=(char)du.read();
}
du.close();
}
}
能读取文件的内容,可除了文件的内容还读出一些“?”,请高手赐教。
import java.io.*;
public class wan3{
public static void main (String args[])throws IOException
{
File f=new File ("D:\\wan.txt");
FileInputStream du=new FileInputStream (f);
int c=du.read();
while (c!=-1){
System.out.print((char)c);
c=(char)du.read();
}
du.close();
}
}
能读取文件的内容,可除了文件的内容还读出一些“?”,请高手赐教。
楼主【wanyoulin】截止到2008-07-03 22:23:22的历史汇总数据(不包括此帖):
发帖的总数量:0 发帖的总分数:0
结贴的总数量:0 结贴的总分数:0
无满意结贴数:0 无满意结贴分:0
未结的帖子数:0 未结的总分数:0
结贴的百分比:---------------------结分的百分比:---------------------
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
import java.io.*;
public class wan3{
public static void main (String args[])throws IOException
{
File f=new File ("D:\\wan.txt");
FileInputStream du=new FileInputStream (f);
String c=du.readLine();
while (c!=null){
System.out.print(c);
c=du.readLine();
}
du.close();
}
}
import java.io.*;
public class wan3{
public static void main (String args[])throws IOException
{
File f=new File ("D:\\wan.txt");
FileInputStream du=new FileInputStream (f);
String c=du.readLine();
while (c!=null){
System.out.print(c);
c=du.readLine();
}
du.close();
}
}
import java.io.*;
public class wan3{
public static void main (String args[])throws IOException
{
File f=new File ("D:\\wan.txt");
FileInputStream du=new FileInputStream (f);
String c=du.readLine();
while (c!=null){
System.out.print(c);
c=du.readLine();
}
du.close();
}
}
网络有问题~提交了N次 不知道帖成没成功
补充
修改后是
import java.io.*;
public class wan3{
public static void main (String args[])throws IOException
{
File f=new File ("D:\\wan.txt");
FileInputStream du=new FileInputStream (f);
BufferedReader br = new BufferedReader(du);//进行封装是为了得到readLine()方法
String c=br.readLine();
while (c!=null){
System.out.print(c);
c=br.readLine();
}
br.close();
du.close();
}
}
import java.io.*;
public class Test1{
public static void main (String args[])throws IOException
{
File f=new File ("D:\\wan.txt");
Reader du=new FileReader(f); ///////忘记修改处
BufferedReader br = new BufferedReader(du);//进行封装是为了得到readLine()方法
String c=br.readLine();
while (c!=null){
System.out.print(c);
c=br.readLine();
}
br.close();
du.close();
}
}