如何用Java编写外部系统接口实现文件导入

2025-02-02 23:27:51
推荐回答(1个)
回答1:

// 定义接口
import java.io.FileOutputStream;

public interface OperateFile {

// 导入文件
public boolean importFile(String path,String name);
// 导出文件
public FileOutputStream exportFile(String path);
}

//..........................................
// 实现子类

import java.io.FileOutputStream;

public class OperateFileImp implements OperateFile{

public boolean importFile(String path, String name) {
// File file = new File(path,name)....
// 在此实现方法,作业嘛…
return false;
}

public FileOutputStream exportFile(String path) {
//........
return null;
}

}
//...................................
//..给外部提供接口....

public class Factory {

private static OperateFile op = null;
public static final int OPERATE_FILE= 1001;
private Factory(){

}
// 实现给外部的接口调用
public OperateFile getInstance(int classType){
if(classType==1001){
op = new OperateFileImp();
return op;
}
else{
throw new RuntimeException("要产生的子类没有定义!");
}
}

}