三行代如下代码,是一个创建文本文档count.txt的类,本人将其"拷贝到其它Class文件中换个名字"就无法创建文本文档count.txt了,比如换成(Notepad类将原码拷入)不信你可以试试,请问这是什么原因?
- Java code
import java.util.Properties;import java.io.*;public class PropertiesFile { public static void main(String[] args) throws Exception { Properties settings=new Properties(); settings.store(new FileOutputStream("count.txt"),"Program is used:"); settings.load(new FileInputStream("count.txt")); } }
------解决方案--------------------
当使用public修饰PropertiesFile,则文件名也必须是PropertiesFile
------解决方案--------------------
输出流没有关闭
------解决方案--------------------
- Java code
import java.util.Properties;import java.io.*;public class Notepad{ public static void main(String[] args) throws Exception { Properties settings=new Properties(); settings.store(new FileOutputStream("count.txt"),"Program is used:"); settings.load(new FileInputStream("count.txt")); } }
------解决方案--------------------
------解决方案--------------------
宿舍快限电了,突然想起来今天没有在csdn回帖,这10分得挣啊!