日期:2014-05-17  浏览次数:20731 次

我有两个java程序,我想一个调用另外一个java的结果怎么弄
Java code

import java.io.*;
import jxl.*;


public class ReadXLS {
public static void main(String args[]){
    try{
        Workbook book=Workbook.getWorkbook(new File("产品分类.map.xls"));
        Sheet sheet=book.getSheet(0);

        for(int i=1;i<sheet.getRows();i++){
            Cell c=sheet.getCell(5,i);
            System.out.println(sheet.getCell(5,i).getContents());
        }

        book.close();
    }catch(Exception e){
        
        System.out.println(e);
    }
}
    
    
}




然后我想用下面这个java程序调用上面的结果
Java code

import java.io.*;
import java.net.HttpURLConnection;

import java.net.*;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;

public class URLUtil {

    public static String getHtml(String urlString){
        try{
            StringBuffer html= new StringBuffer();
            URL url=new URL(urlString);
            HttpURLConnection conn=(HttpURLConnection)url.openConnection();
            InputStreamReader isr=new InputStreamReader(conn.getInputStream());
            BufferedReader br = new BufferedReader(isr);
            String temp;
            

            while((temp = br.readLine())!=null){
                html.append(temp).append("\n");
            }
            br.close();
            isr.close();
            return html.toString();
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
        
    }
    
    
    public static void main(String[] args){
        System.out.println(URLUtil.getHtml("http://www.baidu.com"));
    }
}




------解决方案--------------------
在第二个类里实例化一个?
------解决方案--------------------
1楼说的很清楚啦。。
------解决方案--------------------
Java code

import java.io.*;
import jxl.*;


public class ReadXLS {
public void call(){
    try{
        Workbook book=Workbook.getWorkbook(new File("产品分类.map.xls"));
        Sheet sheet=book.getSheet(0);

        for(int i=1;i<sheet.getRows();i++){
            Cell c=sheet.getCell(5,i);
            System.out.println(sheet.getCell(5,i).getContents());
        }

        book.close();
    }catch(Exception e){
        
        System.out.println(e);
    }
}
    
    
}