public class Pxto{
public getOp(){
String str1="xxxx";
String str2="xxxx";
boolean bl=OPwriter.createTxtFile(str1,str2);
//.....
}
OPwriter没有实例对象!
public getOp(){
String str1="xxxx";
String str2="xxxx";
boolean bl=OPwriter.createTxtFile(str1,str2);
//.....
}
OPwriter没有实例对象!
解决方案 »
- TreeSet集合为什么要实现Comparable
- 关于HQL语句
- jsp<a href>传值
- public Object fun() 不用返回有用的对象时 怎么写?
- SWT 怎么做出右下脚慢慢升出shell的效果??就象QQ系统消息那样...
- 自以为是高手,初次接触java,是看了 java.lang.reflect.Proxy 的newProxyInstance方法 的源码30分钟后, 头晕了。
- float类型相减问题,想不通
- ThinkInJava里的一个例程,没看明白,请指点。
- 在java中怎样实现将主机字节顺序转换成网络字节顺序
- 如何写下面语句,!!?来者有分!
- 时间段计算问题 急急,在线等待
- 请教关于PrintWriter类的几个问题
public static boolean createTxtFile(String content,String file)
{
System.out.printl("The file is creating...");
//do something...
}
}
并没有打印出来,而其文件也没有被创建,也没有报错
public class Pxto{
public getOp(){
String str1="xxxx";
String str2="xxxx";
boolean bl=OPwriter.createTxtFile(str1,str2);
//.....
}你上面的这个方法写错了。
public getOp()
这里如果没有返回值应该写为:
public void getOp()
类2:
public class Pxto{
public void getOp(){
String str1="xxxx";
String str2="xxxx";
boolean bl=OPwriter.createTxtFile(str1,str2);
//.....
}
当执行到boolean bl=OPwriter.createTxtFile(str1,str2);时,一定会被调用
楼主一定是还有什么地方遗漏了
boolean bl=OPwriter.createTxtFile(str1,str2);
和
//do something...
前输出打印语句
看看结果到底是哪个没有执行说不定是getOp()
原来的代码:
public static boolean createTxtFile(String content,String thefile) //根据filename 创建以content 为内容的文件
{
String str = content; //文件内容
String filename=thefile; //文件名
System.out.println("File creating begin...");
if(str==null || str.length()<0 || filename==null || filename.length()<0) {
System.out.println("the String Content or File Name is null...");
return false;
} try
{
File f = new File(filename);
if(!f.exists()) //如果文件不存,则建立
f.createNewFile();
PrintWriter pw = new PrintWriter(new FileOutputStream(filename));
System.out.println("The File is Created...");
pw.println(str);//写内容
pw.close();
}catch(IOException e)
{
e.printStackTrace();
return false;
}
return true;
}
以上代码使createTxtFile()没被执行该过以后:
public static boolean createTxtFile(String content,String thefile) //根据filename 创建以content 为内容的文件
{
String str = content; //文件内容
String filename=thefile; //文件名
System.out.println("File creating begin..."); try
{
if(str==null || str.length()<0 || filename==null || filename.length()<0) {
System.out.println("the String Content or File Name is null...");
return false;
}
File f = new File(filename);
if(!f.exists()) //如果文件不存,则建立
f.createNewFile();
PrintWriter pw = new PrintWriter(new FileOutputStream(filename));
System.out.println("The File is Created...");
pw.println(str);//写内容
pw.close();
}catch(IOException e){
e.printStackTrace();
return false;
}
return true;
}一切OK!郁闷啊