日期:2014-05-20  浏览次数:20875 次

如何从文件中读入一行字符串
DataInputStream   ServerConfigFile;
ServerConfigFile   =   new   DataInputStream(new   FileInputStream( "srvcfg.txt "));
try{
IntString   =   ServerConfigFile.readLine();
}
                                      catch   (IOException   ioe){
consoleOutput.append( "\n   Error   reading   the   #   servers ");
}
提示readLine   is   deprecated

------解决方案--------------------
IntString = ServerConfigFile.readLine();
??????
------解决方案--------------------
import java.io.BufferedReader;
import java.io.*;

/**
* @author Administrator
*/
public class Inputtest {

public static void main(String[] args) throws Exception{
FileInputStream fi =new FileInputStream( "C://a.txt ");
BufferedReader br = new BufferedReader(new InputStreamReader(fi));
String c =br.readLine();
System.out.println(c);
}
}
//一切OK!
------解决方案--------------------
BufferedReader in = new BufferedReader(new FileReader(file));
str = in.readLine()
------解决方案--------------------
try {
BufferedReader in = new BufferedReader(new FileReader( "infilename "));
String str;
while ((str = in.readLine()) != null) {
// 这里处理读出来的字符串str
}
in.close();
} catch (IOException e) {
}
------解决方案--------------------
你要是用DateInputStream的话,就用readUTF()

readLine()
已过时。 该方法无法将字节正确转换为字符。从 JDK 1.1 开始,读取文本行的首选方法是使用 BufferedReader.readLine() 方法。对于使用 DataInputStream 类读取文本行的程序,可以转而使用 BufferedReader 类,实现方式是通过将以下形式的代码:
DataInputStream d = new DataInputStream(in);
替换为:
BufferedReader d
= new BufferedReader(new InputStreamReader(in));