忘了是啥,很高级的样子
public class Main {
public static void main(String[] args) throws Exception {
Socket socket=new Socket("12.29.09",1000);
String str="qisong";
OutputStream os=socket.getOutputStream();
os.write(str.getBytes());
InputStream is=socket.getInputStream();
InputStreamReader isr=new InputStreamReader(is);
int b;
while((b=isr.read())!=-1){
System.out.println((char)b);
}
socket.close();
}
}
public class test {
public static void main(String[] args) throws IOException {
ServerSocket ss=new ServerSocket(1000);
Socket socket=ss.accept();
InputStream is=socket.getInputStream();
InputStreamReader isr=new InputStreamReader(is);
int b;
while((b=isr.read())!=-1){
System.out.println((char)b);
}
String str="uuidscisndc";
OutputStream os=socket.getOutputStream();
os.write(str.getBytes());
socket.close();
ss.close();
}
}
上传文件到客户端
public class Main {
public static void main(String[] args) throws Exception {
Socket socket=new Socket("128.1.89",1000);
BufferedInputStream bis=new BufferedInputStream(new FileInputStream("a.ddkd//ada"));
BufferedOutputStream bos=new BufferedOutputStream(socket.getOutputStream());
byte[] bytes=new byte[1024];
int len;
while((len= bis.read(bytes))!=-1){
bos.write(bytes,0,len);
}
socket.shutdownInput();
BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
String line=br.readLine();
System.out.println(line);
socket.close();
}
}
public class test {
public static void main(String[] args) throws IOException {
ServerSocket ss=new ServerSocket(1000);
Socket socket=ss.accept();
BufferedInputStream bis=new BufferedInputStream(socket.getInputStream());
BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("a\\a.jpg"));
int len;
byte[] bytes=new byte[1024];
while((len= bis.read(bytes))!=-1){
bos.write(bytes,0,len);
}
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
bw.write("yes");
bw.newLine();
bw.flush();
socket.close();
ss.close();
}
}
解决文件名重复的问题
public static void main(String[] args) throws Exception {
String str= UUID.randomUUID().toString().replace("-","*");
System.out.println(str);
}
获取构造方法
public class Main {
public static void main(String[] args) throws Exception {
class clazz=Class.forName("demo");
Constructor[] cons=clazz.getConstructors();
for(Constructor con:cons){
System.out.println(con);
}}
}
获取字节码文件的对象
public class Main {
public static void main(String[] args) throws Exception {
Class ca=Class.forName("demo");
Field[] fields=ca.getFields();
for(Field field:fields){
System.out.println(field);
}
}
}
完了,虽然有点水,但是java基础算是基本掌握了(^-^)ovo
扣1送地狱火.......picture