package myLib; import java.io.IOException; /** * * @author ZhuTao * 2006.5.4 * @version 1.0 * */ public class IOModule { //The max length of string you want to get; public static final int MAX = 1000; /** * This method is used to get int value. * @return A int. * @throws IOException */ public static int getInt() { int i = 0; try{ i = System.in.read(); }catch(IOException e){System.out.println("Read Error!");}; return i; } /** * This method is used to get a string. * @return a string. */ public static String getString() { String s; byte[]t = new byte[MAX]; int length = 0; try{ length = System.in.read(t); }catch(IOException e){System.out.println("Read Error!");}; s = new String(t,0,length-2);//过滤掉回车换行符; return s; } /** * This method is used to get a long value. * @return a long number. */ public static long getLong() { long i = 0; String s; int length = 0; byte[]t = new byte[20]; try{ length = System.in.read(t); }catch(IOException e){System.out.println("Read Error!");}; s = new String(t,0,length-2); i = Long.parseLong(s); return i; } /** * This method is used to get a float number. * @return a float number. */ public static float getFloat() { float i = 0; String s; int length = 0; byte[]t = new byte[20]; try{ length = System.in.read(t); }catch(IOException e){System.out.println("Read Error!");}; s = new String(t,0,length-2); i = Float.parseFloat(s); return i; } /** * This method is used to get a double number. * @return a double number. */ public static double getDouble() { double i = 0; String s; byte[]t = new byte[20]; int length = 0; try{ length = System.in.read(t); }catch(IOException e){System.out.println("Read Error!");}; s = new String(t,0,length-2); i = Double.parseDouble(s); return i; } } 然后我用jar cvf myLib.jar IOModule.class生成myLib.jar然后在一个工程中如何导入才可以使用?你们上面说的我试过的啊
Properties->Java Build Path->Libraries->Add External Jars...
import java.io.IOException;
/**
*
* @author ZhuTao
* 2006.5.4
* @version 1.0
*
*/
public class IOModule {
//The max length of string you want to get;
public static final int MAX = 1000;
/**
* This method is used to get int value.
* @return A int.
* @throws IOException
*/
public static int getInt()
{
int i = 0;
try{
i = System.in.read();
}catch(IOException e){System.out.println("Read Error!");};
return i;
}
/**
* This method is used to get a string.
* @return a string.
*/
public static String getString()
{
String s;
byte[]t = new byte[MAX];
int length = 0;
try{
length = System.in.read(t);
}catch(IOException e){System.out.println("Read Error!");};
s = new String(t,0,length-2);//过滤掉回车换行符;
return s;
}
/**
* This method is used to get a long value.
* @return a long number.
*/
public static long getLong()
{
long i = 0;
String s;
int length = 0;
byte[]t = new byte[20];
try{
length = System.in.read(t);
}catch(IOException e){System.out.println("Read Error!");};
s = new String(t,0,length-2);
i = Long.parseLong(s);
return i;
}
/**
* This method is used to get a float number.
* @return a float number.
*/
public static float getFloat()
{
float i = 0;
String s;
int length = 0;
byte[]t = new byte[20];
try{
length = System.in.read(t);
}catch(IOException e){System.out.println("Read Error!");};
s = new String(t,0,length-2);
i = Float.parseFloat(s);
return i;
}
/**
* This method is used to get a double number.
* @return a double number.
*/
public static double getDouble()
{
double i = 0;
String s;
byte[]t = new byte[20];
int length = 0;
try{
length = System.in.read(t);
}catch(IOException e){System.out.println("Read Error!");};
s = new String(t,0,length-2);
i = Double.parseDouble(s);
return i;
}
}
然后我用jar cvf myLib.jar IOModule.class生成myLib.jar然后在一个工程中如何导入才可以使用?你们上面说的我试过的啊
myLib.jar
|-- META-INF
| `-- MANIFEST.MF
`-- myLib
`--IOModule.class
myLib.jar
|-- META-INF
| `-- MANIFEST.MF
`-- myLib
`--IOModule.class
我的结构是:
myLib.jar
|-- META-INF
| `-- MANIFEST.MF
`-- default package
`--IOModule.class
请问这样有什么问题吗?