這是我的代碼之後描述的錯誤。方法在緩衝寫入器中寫入不接受參數
import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.*;
import java.util.*;
public class FileDemo {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter no of persons");
int person=sc.nextInt();
File myfile = new File("E:/java/myfile.txt");
BufferedWriter output = new BufferedWriter(new FileWriter(myfile));
for(int i=0;i<person;i++)
{
System.out.println("Enter Firstname");
String firstname=sc.next();
System.out.println("Lastname");
String lastname=sc.next();
System.out.println("mobnum");
int mobnum=sc.nextInt();
output.write("+firstname+" "+lastname+" "+mobnum+");
}
output.close();
/*** here change fis to Reader ***/
FileInputStream fis=new FileInputStream("myfile.txt");
BufferedReader br=new BufferedReader(fis);
int i=1;
String str=null;
while((str=br.readLine())!=null)
{
System.out.println("Person"+i);
StringTokenizer st=new StringTokenizer(str,"");
System.out.println("FirstName"+st.nextToken());
System.out.println("lastname"+st.nextToken());
System.out.println("country"+st.nextToken());
}
}
}
在這裏,我得到錯誤,在作家型的方法寫(字符串)不適用的參數(字符串,字符串)。
謝謝你..在上面的程序我得到另一個錯誤時,FIS的FileInputStream新=的FileInputStream( 「myfile.txt的」); BufferedReader br = new BufferedReader(fis);要求將fis更改爲Reader .. – karna 2013-04-26 06:29:35
您需要BufferedReader和FileInputStream之間的InputStreamReader,如下所示:FileInputStream fis = new FileInputStream(「myfile.txt」); BufferedReader br = new BufferedReader(new InputStreamReader(fis)); – CloudyMarble 2013-04-26 06:35:29