okay i will give tutorial how to make program to send and receive big file with java using NetBeans. here we will create both programs in one package. i will create two program to send and recivied file here.
package file;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JOptionPane;
public class Send {
public static void main(String[] args)throws IOException {
String namalokasifile= JOptionPane.showInputDialog("masukkan lokasi file"+"(e.g E:\\nama.format):");
int Port =Integer.parseInt(JOptionPane.showInputDialog("Input Your Port : "));
ServerSocket sock=new ServerSocket (Port);
JOptionPane.showMessageDialog(null,"server started");
JOptionPane.showMessageDialog(null,"waiting client");
Socket soc =sock.accept();
BufferedOutputStream bos = new BufferedOutputStream (soc.getOutputStream());
FileInputStream fis=new FileInputStream(namalokasifile);
BufferedInputStream bis = new BufferedInputStream(fis);
int n=-1;
byte[] buffer;
buffer = new byte [70022386];
while((n= bis.read(buffer))>-1)
{
bos.write(buffer,0,n);
System.out.println("bytes="+n);
bos.flush();}}}
package Send;import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JOptionPane;
public class Send writing class names must be capitalized, and should not use spaces.Throws IOException Is A Method That Reads String Data Inputint Port =Integer.parseInt(JOptionPane.showInputDialog with JOptionPane input method.java.net.ServerSocket used by Server to connections.sock.accept() also called socket programing.BufferedInputStream andBufferedOutputStream can be used for reading and writing binary data from a file.byte[] buffer; function To read a number of data bytes.System.out.println serves to print the writing to the screen.package file;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.Socket;
import javax.swing.JOptionPane;
public class ReciveBig {
public static void main(String[] args) throws IOException {
int Port =Integer.parseInt(JOptionPane.showInputDialog("Input Your Port : "));
String IP= JOptionPane.showInputDialog("Input Your IP Server : ");
String save= JOptionPane.showInputDialog("masukkan tempat lokasi penyimpanan (e.g E:\\nama_file.Format_file) : ");
Socket sock=new Socket(IP,Port);
File file=new File(save);
BufferedInputStream bis=new BufferedInputStream(sock.getInputStream());
FileOutputStream fos = new FileOutputStream(file);
int n;
byte[] buffer = new byte[70022386];
JOptionPane.showMessageDialog(null,"Connected");
while ((n = bis.read(buffer)) > -1) {
System.out.println("bytes="+n);
fos.write(buffer, 0, n);
// if(n<(1024)){
// fos.close();
// bis.close();
// break;
}
fos.flush();
}
JOptionPane.showMessageDialog(null,"File Received");
}}
OKE TUTORIAL HAS DONE