关于文件输入,用scanner,上出现问题了,求指点,巴拉巴拉巴拉……丧气……
import java.io.*;import java.util.*;
public class test {
public static void main(String[] args)
{
Scanner in=new Scanner(File("c:\\1.txt"));//在此位置出错,详情:"The method File(String) is undefined for the type test "!!!
}
}
----------------解决方案--------------------------------------------------------
好吧,这个问题莫名其妙地解决了,但是又出现了另一个问题,修改的代码执行之后,在控制端没有输出任何东西,哎呀,只会“输入”不会“读取”啊,泪求指点……
程序代码:
import java.io.*;
import java.util.*;
public class test
{
public static void main (String[] args) throws FileNotFoundException
{
PrintWriter wr=new PrintWriter("c:\\1.txt");
wr.write("纠结啊纠结……");
wr.close();
Scanner out =new Scanner (new File ("c:\\1.txt"));
out.next();
out.close();
}
}
import java.util.*;
public class test
{
public static void main (String[] args) throws FileNotFoundException
{
PrintWriter wr=new PrintWriter("c:\\1.txt");
wr.write("纠结啊纠结……");
wr.close();
Scanner out =new Scanner (new File ("c:\\1.txt"));
out.next();
out.close();
}
}
!!!!!!!\*但求最简单有效的读取方法……orz……………………orz………………orz……………………*\
[ 本帖最后由 hduhjj 于 2010-11-11 16:25 编辑 ]
----------------解决方案--------------------------------------------------------
以下是引用hduhjj在2010-11-11 16:09:59的发言:
好吧,这个问题莫名其妙地解决了,但是又出现了另一个问题,修改的代码执行之后,在控制端没有输出任何东西,哎呀,只会“输入”不会“读取”啊,泪求指点……import java.io.*;
import java.util.*;
public class test
{
public static void main (String[] args) throws FileNotFoundException
{
PrintWriter wr=new PrintWriter("c:\\1.txt");
wr.write("纠结啊纠结……");
wr.close();
Scanner out =new Scanner (new File ("c:\\1.txt"));
out.next();
out.close();
}
}
!!!!!!!\*但求最简单有效的读取方法……orz……………………orz………………orz……………………*\
好吧,这个问题莫名其妙地解决了,但是又出现了另一个问题,修改的代码执行之后,在控制端没有输出任何东西,哎呀,只会“输入”不会“读取”啊,泪求指点……import java.io.*;
import java.util.*;
public class test
{
public static void main (String[] args) throws FileNotFoundException
{
PrintWriter wr=new PrintWriter("c:\\1.txt");
wr.write("纠结啊纠结……");
wr.close();
Scanner out =new Scanner (new File ("c:\\1.txt"));
out.next();
out.close();
}
}
!!!!!!!\*但求最简单有效的读取方法……orz……………………orz………………orz……………………*\
程序代码:
import java.io.*;
import java.util.*;
public class test
{
public static void main (String[] args) throws FileNotFoundException
{
PrintWriter wr=new PrintWriter("c:\\1.txt");
wr.write("纠结啊纠结……");
wr.close();
Scanner in =new Scanner (new FileReader ("c:\\1.txt"));
String str = in.nextLine();
in.close();
System.out.println(str);
}
}
import java.util.*;
public class test
{
public static void main (String[] args) throws FileNotFoundException
{
PrintWriter wr=new PrintWriter("c:\\1.txt");
wr.write("纠结啊纠结……");
wr.close();
Scanner in =new Scanner (new FileReader ("c:\\1.txt"));
String str = in.nextLine();
in.close();
System.out.println(str);
}
}
----------------解决方案--------------------------------------------------------
回复 3楼 lampeter123
谢谢大大,问题已经解决了的,用的是new Scaner (new File("c:\\1.txt")),还是谢谢大大, ----------------解决方案--------------------------------------------------------