* 取得当前目录下文件对象
* @return
*/
public static Iterator getFiles(File currentFile) {
Vector vector = new Vector()
File afile[] = currentFile.listFiles()
for (int i = 0i <afile.lengthi++)
if (afile[i].isFile())
vector.add(afile[i])
return vector.iterator()
}
/**
* 取得当前目录下的子目录对象列表
* @return
*/
public static Iterator getAllDirectories(File currentFile) {
Vector vector = new Vector()
File afile[] = currentFile.listFiles()
//vector.add(new File(documentRoot, relativeFile + File.separator + "."))
try {
vector.add(new File(currentFile.getCanonicalFile() + File.separator + ".."))
for (int i = 0i <afile.lengthi++)
if (afile[i].isDirectory())
vector.add(afile[i])
} catch (IOException e) {
if (log.isErrorEnabled()) log.error(e)
}
return vector.iterator()
}
/**
* 取得当前目录下的子目录对象列表
* @return
*/
public static Iterator getDirectories(File currentFile) {
Vector vector = new Vector()
File afile[] = currentFile.listFiles()
for (int i = 0i <afile.lengthi++)
if (afile[i].isDirectory())
vector.add(afile[i])
return vector.iterator()
}
/**
* 将内容写入文件
* @param file
* @param content
* @throws IOException
*/
public static void writeFile(String file, String content)
throws IOException {
PrintWriter printwriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),BIND_ENCODING)))
printwriter.write(content)
printwriter.close()
if (printwriter.checkError())
if (log.isErrorEnabled())
log.error("Error encountered while writing the file!")
else
return
}
代码太长,分批发.
public class complie {int i,j
public complie(int i,int j)//构建一个复数类
{
this.i=i
this.j=j
}
complie add(complie c)//复数加法
{
int l,k
l=c.i+i
k=c.j+j
return (new complie(l,k))
}
complie cut(complie c)//复数减法
{
int l,k
l=i-c.i
k=j-c.j
return (new complie(l,k))
}
void ToString()//将复数输出
{
System.out.println("复数为:"+i+"+"+j+"i")
}
public static void main(String[] args)
{
complie a=new complie(4,5)
complie b=new complie(2,3)
System.out.println("构造的复数类为:")
a.ToString()
b.ToString()
System.out.println("运算复数a+b=:")
a.add(b).ToString()
System.out.println("运算复数a-b=:")
a.cut(b).ToString()
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)