在客户端类中,我有硬编码int inch = 12; int feet = 2;但我的要求是必须的 创建具有几英寸和英尺的单独文件。我希望获得所有英寸和英尺的值 文件及其相关回复。
我的客户代码: 公共类TempClient {
static final String REST_URI = "http://localhost:8081/CustomerDemo";
static final String INCH_TO_FEET = "/ConversionService/InchToFeet/";
static final String FEET_TO_INCH = "/ConversionService/FeetToInch/";
public static void main(String[] args) {
int inch=12;
int feet=2;
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(REST_URI);
WebResource addService = service.path("rest").path(INCH_TO_FEET+inch);
System.out.println("INCH_TO_FEET Response: " + getResponse(addService));
System.out.println("INCH_TO_FEET Output as XML: " + getOutputAsXML(addService));
System.out.println("---------------------------------------------------");
WebResource subService = service.path("rest").path(FEET_TO_INCH+feet);
System.out.println("FEET_TO_INCH Response: " + getResponse(subService));
System.out.println("FEET_TO_INCH Output as XML: " + getOutputAsXML(subService));
System.out.println("---------------------------------------------------");
}
private static String getResponse(WebResource service) {
return service.accept(MediaType.TEXT_XML).get(ClientResponse.class).toString();
}
private static String getOutputAsXML(WebResource service) {
return service.accept(MediaType.TEXT_XML).get(String.class);
}
}
答案 0 :(得分:0)
假设您有一个名为data.txt的文件,如
1
2
3
4
5
6
7
你可以做点什么
BufferedReader br = new BufferedReader(new FileReader(new File("C:\\Users\\Leo\\workspace\\STackOverflow\\src\\data.txt")));
String line = null;
List<Integer> inches = new ArrayList<Integer>();
while((line = br.readLine())!=null){
inches.add(Integer.parseInt(line));
}
br.close();
for(Integer inch:inches){
WebResource addService = service.path("rest").path(INCH_TO_FEET+inch);
System.out.println("INCH_TO_FEET Response: " + getResponse(addService));
System.out.println("INCH_TO_FEET Output as XML: " + getOutputAsXML(addService));
System.out.println("---------------------------------------------------");
}
然后你可以为脚做同样的事情