我对java文件程序有疑问 [英] I have question about java file program

查看:57
本文介绍了我对java文件程序有疑问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了以下代码并导入了必要的文件仍然出错。

找不到符号构造函数FileWriter(java.lang.String)

找不到符号方法写(java.lang.String)





怎么办?

我已经看过视频了那还是不行吗?



我尝试过:



I have write the following code and import the necessary file still error come.
cannot find symbol constructor FileWriter(java.lang.String)
cannot find symbol method write(java.lang.String)


What to do?
I have already seen the video of that but still not working?

What I have tried:

import  java.io.*;
import  java.io.File;
import  java.io.Reader;
import java.io.Writer.*;
class writer
{
	public static void main (String[] args) {
		File f1 = new File("abc.txt");

		try
		{
	FileWriter 	fw = new FileWriter(f1);
			String s = "Hello World";
		fw.write(s);
			
		}
		catch(Exception e)
		{
			
		}
	
	}
}

推荐答案

我建​​议阅读这个出色的解释 [ ^ ] 找不到符号错误。



现在,看看此代码 [ ^ ]:

I'd suggest to read this excellent explanation[^] of cannot find symbol error.

Now, take a look at this code[^]:
import java.io.*;
public class FileRead {

   public static void main(String args[])throws IOException {
      File file = new File("Hello1.txt");
      
      // creates the file
      file.createNewFile(); //you missed that
      
      // creates a FileWriter Object
      FileWriter writer = new FileWriter(file); 
      
      // Writes the content to the file
      writer.write("Hello World!"); 
      writer.flush(); //
      writer.close(); //

      // Creates a FileReader Object
      FileReader fr = new FileReader(file); 
      char [] a = new char[50];
      fr.read(a);   // reads the content to the array
      
      for(char c : a)
         System.out.print(c);   // prints the characters one by one
      fr.close();
   }
}



你看到了区别吗?



试试!


Do you see the difference?

Try!


你应该首先找到像这样的简单错误的文档: FileWriter(Java Platform SE 7) [ ^ ]。
The first place you should look for simple errors like this is the documentation: FileWriter (Java Platform SE 7 )[^].


这篇关于我对java文件程序有疑问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆