Streaming audio from microphone with Java - java

I'm developing a project which requires me to stream audio from microphone from a client to a server. The code shown below is what I have written. When I run both the client and server code the audio is not streamed live. In fact the audio from the client is stored in the buffer and when I terminate the execution of the client side code the audio from the buffer on the server gets output to the speaker. What am I doing wrong? (I'm developing on eclipse)
server:
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.TargetDataLine;
//import org.apache.commons.io.output.ByteArrayOutputStream;
public class ServerStream {
private OutgoingSoudnListener osl = new OutgoingSoudnListener();
boolean outVoice = true;
AudioFormat format = getAudioFormat();
private ServerSocket serverSocket;
Socket server;
private AudioFormat getAudioFormat() {
float sampleRate = 16000.0F;
int sampleSizeBits = 16;
int channels = 1;
boolean signed = true;
boolean bigEndian = false;
return new AudioFormat(sampleRate, sampleSizeBits, channels, signed, bigEndian);
}
public ServerStream() throws IOException{
try{
System.out.println("Creating Socket...");
serverSocket = new ServerSocket(3000);
osl.runSender();
}catch(Exception e){
e.printStackTrace();
}
}
class OutgoingSoudnListener{
public void runSender(){
try{
server = serverSocket.accept();
System.out.println("Listening from mic.");
DataOutputStream out = new DataOutputStream(server.getOutputStream());
DataLine.Info micInfo = new DataLine.Info(TargetDataLine.class,format);
TargetDataLine mic = (TargetDataLine) AudioSystem.getLine(micInfo);
mic.open(format);
System.out.println("Mic open.");
byte tmpBuff[] = new byte[mic.getBufferSize()/5];
mic.start();
while(outVoice) {
System.out.println("Reading from mic.");
int count = mic.read(tmpBuff,0,tmpBuff.length);
if (count > 0){
System.out.println("Writing buffer to server.");
out.write(tmpBuff, 0, count);
}
}
mic.drain();
mic.close();
System.out.println("Stopped listening from mic.");
}catch(Exception e){
e.printStackTrace();
}
}
}
public static void main (String args[]) throws IOException{
new ServerStream();
}
}
client:
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
import org.apache.commons.io.IOUtils;
public class ClientStream{
public ClientStream() throws IOException{
isl.runListener();
}
private IncomingSoundListener isl = new IncomingSoundListener();
AudioFormat format = getAudioFormat();
InputStream is;
Socket client;
String serverName = "192.168.2.8";
int port=3000;
boolean inVoice = true;
private AudioFormat getAudioFormat(){
float sampleRate = 16000.0F;
int sampleSizeBits = 16;
int channels = 1;
boolean signed = true;
boolean bigEndian = false;
return new AudioFormat(sampleRate, sampleSizeBits, channels, signed, bigEndian);
}
class IncomingSoundListener {
public void runListener(){
try{
System.out.println("Connecting to server:"+serverName+" Port:"+port);
client = new Socket(serverName,port);
System.out.println("Connected to: "+client.getRemoteSocketAddress());
System.out.println("Listening for incoming audio.");
DataLine.Info speakerInfo = new DataLine.Info(SourceDataLine.class,format);
SourceDataLine speaker = (SourceDataLine) AudioSystem.getLine(speakerInfo);
speaker.open(format);
speaker.start();
while(inVoice){
is = client.getInputStream();
byte[] data = IOUtils.toByteArray(is);
ByteArrayInputStream bais = new ByteArrayInputStream(data);
AudioInputStream ais = new AudioInputStream(bais,format,data.length);
int bytesRead = 0;
if((bytesRead = ais.read(data)) != -1){
System.out.println("Writing to audio output.");
speaker.write(data,0,bytesRead);
// bais.reset();
}
ais.close();
bais.close();
}
speaker.drain();
speaker.close();
System.out.println("Stopped listening to incoming audio.");
}catch(Exception e){
e.printStackTrace();
}
}
}
public static void main(String [] args) throws IOException{
new ClientStream();
}
}

The problem is in client side,
in the line
byte[] data = IOUtils.toByteArray(is);
It deals with the object itself, not with the content.
So, you must change it to this:
byte[] data = new byte[1024];

I am not familiar with this, so don't get mad if I am way off here, but reading the api for DataLine it seems to function like a buffer, that you have to flush or drain in this case to get the output. Have you attempted to put the mic.drain()/speaker.drain() command in the while loop?

Related

java: Transfer a file to the server and get the file from the server in upper case

i want to send a .txt file from the client to server and get it back in upper case.
But this code do nothing.can anyone tell what is wrong here..?
SERVER : getting file from client and sending it back in upper case to the client.
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Arrays;
public class Assignment4_Server {
public static void main(String[] args) throws IOException {
byte[] bytearray = new byte[4096];
try (ServerSocket ss = new ServerSocket(4444)) {
Socket s = ss.accept();
InputStream is = s.getInputStream();
OutputStream os = s.getOutputStream();
int count;
String data = null ;
while((count = is.read(bytearray))>0){
data = Arrays.toString(bytearray).toUpperCase();
byte[] bytearrayout = data.getBytes();
os.write(bytearrayout);
}
s.close();
}
}
}
CLIENT : sending text.txt file to the server and getting file back after converted in upper case.
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
public class Assignment4_client {
public static void main(String[] args) throws IOException {
File file = new File("test.txt");
byte[] bytearray = new byte[4096];
Socket sc = new Socket("localhost",4444);
//send file
int countS , countR;
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
OutputStream os = sc.getOutputStream();
while((countS = bis.read(bytearray))>0){
os.write(bytearray);
}
//recieve file in uppercase from server
InputStream is = sc.getInputStream();
byte[] bytearray2 = new byte[4096];
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
while((countR = is.read(bytearray2))>0){
bos.write(bytearray2);
}
}
}
Here is a code that should help you. But before reading it you should be aware of what is happening:
Your client is not sending a 'stop reading' information to the server (read the client code below). That's why the server is stuck in the while loop when it is trying to read the data sent by the client. That is probably why you have tried to send the data back directly to the client. Shut down the socket output from the client side to respect the Socket contract and correctly free the socket (see TCP/IP).
The solution given doesn't take in account that the server should stay up after it has done its duty. Then, the server will not be able to serve more than one client at a time. This server is offering a one time service, which is pointless. To overcome this issue you should put everything in a while loop and bind every new server process into a new thread (I let you do that, its quite a joy).
The server doesn't take in account the whole size of the data an it could possibly run into an out of memory error if the data is too heavy. You should find a way to avoid this problem in a real implementation.
Both program should catch the exception and log it somewhere so you could be aware of any errors.
Writing a server is not so simple. You should normally write some kind of protocol with headers and other stuff like that. To avoid that, use objects like ObjectOutputStream and ObjectInputStream but it has some limitation like constraining your server in the Java world.
CLIENT
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.net.Socket;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
public class Client {
public void send(File file)
{
Socket sc = null;
try
{
byte[] bytearray = new byte[4096];
sc = new Socket("localhost", 4444);
// 1. Read the file, send its content, close it.
int count;
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
OutputStream os = sc.getOutputStream();
while((count = bis.read(bytearray))>0)
{
os.write(bytearray);
}
fis.close();
sc.shutdownOutput();
// 2. Delete old file, receive data, write it to new File.
InputStream is = sc.getInputStream();
bytearray = new byte[4096];
// Eventually do what you want with the file: new one, append, etc.
file.delete();
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
count = 0;
while((count = is.read(bytearray)) > 0)
{
bos.write(bytearray, 0, count);
}
fos.close();
bos.close();
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
if (sc != null)
{
try
{
sc.close();
} catch (IOException e) {}
}
}
}
}
SERVER
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class Server
{
Server()
{
Socket s = null;
byte[] bytearray = new byte[4096];
try (ServerSocket ss = new ServerSocket(4444))
{
s = ss.accept();
InputStream is = s.getInputStream();
// 1. Recieve data and put it to UpperCase.
String data = "";
int count;
while((count = is.read(bytearray)) > 0)
{
data += new String(bytearray, 0, count);
}
data = data.toUpperCase();
System.out.println(data);
// 2. Send back data.
OutputStream os = s.getOutputStream();
os.write(data.getBytes());
os.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
TEST PROGRAM
This one should help you to test your both programs in the same project in an IDE.
import java.io.File;
public class Test
{
public static void main(String[] args)
{
Client c = new Client();
(new Thread()
{
public void run()
{
Server s = new Server();
}
}).start();
c.send(new File("test.txt"));
}
}
What is wrong here is two simple things.
The server is reading until end of stream, on a socket that must be used for the reply. The client therefore cannot close it after sending the request to provide the EOS, so it must shutdown the socket for output after sending the request.
Your copy loops are wrong. The general form is:
while ((count = in.read(buffer)) > 0)
{
out.write(buffer, 0, count);
}
You are ignoring the read count when writing, so you will write junk at end of stream, or any other time that read() doesn't fill buffer, which can be any time at all.

Client-Server Based Audio Live Streaming in java using Socket

Given code is intended to do live audio streaming between client and server using java socket, but problem is that when I run this project, the client starts recording the sound and send it to receiver(server) side. Then Server buffers the received the sound but does not play it simultaneously.But when the client is closed, the server starts playing the sound.Please help me. I need that server must play received sound simultaneously.
\client
import java.io.*;
import java.net.*;
import java.sound.sampled.*;
import org.apache.commons.io.IOUtils;
public class ClientStream{
public ClientStream() throws IOException{
isl.runListener();
}
private IncomingSoundListener isl = new IncomingSoundListener();
AudioFormat format = getAudioFormat();
InputStream is;
Socket client;
String serverName = "192.168.2.8";
int port=3000;
boolean inVoice = true;
private AudioFormat getAudioFormat(){
float sampleRate = 16000.0F;
int sampleSizeBits = 16;
int channels = 1;
boolean signed = true;
boolean bigEndian = false;
return new AudioFormat(sampleRate, sampleSizeBits, channels, signed, bigEndian);
}
class IncomingSoundListener {
public void runListener(){
try{
System.out.println("Connecting to server:"+serverName+" Port:"+port);
client = new Socket(serverName,port);
System.out.println("Connected to: "+client.getRemoteSocketAddress());
System.out.println("Listening for incoming audio.");
DataLine.Info speakerInfo = new DataLine.Info(SourceDataLine.class,format);
SourceDataLine speaker = (SourceDataLine) AudioSystem.getLine(speakerInfo);
speaker.open(format);
speaker.start();
while(inVoice){
is = client.getInputStream();
byte[] data = IOUtils.toByteArray(is);
ByteArrayInputStream bais = new ByteArrayInputStream(data);
AudioInputStream ais = new AudioInputStream(bais,format,data.length);
int bytesRead = 0;
if((bytesRead = ais.read(data)) != -1){
System.out.println("Writing to audio output.");
speaker.write(data,0,bytesRead);
// bais.reset();
}
ais.close();
bais.close();
}
speaker.drain();
speaker.close();
System.out.println("Stopped listening to incoming audio.");
}catch(Exception e){
e.printStackTrace();
}
}
}
public static void main(String [] args) throws IOException{
new ClientStream();
}
}
\server
import java.io.*;
import java.net.*;
import java.sound.sampled.*;
public class ServerStream {
private OutgoingSoudnListener osl = new OutgoingSoudnListener();
boolean outVoice = true;
AudioFormat format = getAudioFormat();
private ServerSocket serverSocket;
Socket server;
private AudioFormat getAudioFormat() {
float sampleRate = 16000.0F;
int sampleSizeBits = 16;
int channels = 1;
boolean signed = true;
boolean bigEndian = false;
return new AudioFormat(sampleRate, sampleSizeBits, channels, signed, bigEndian);
}
public ServerStream() throws IOException{
try{
System.out.println("Creating Socket...");
serverSocket = new ServerSocket(3000);
osl.runSender();
}catch(Exception e){
e.printStackTrace();
}
}
class OutgoingSoudnListener{
public void runSender(){
try{
server = serverSocket.accept();
System.out.println("Listening from mic.");
DataOutputStream out = new DataOutputStream(server.getOutputStream());
DataLine.Info micInfo = new DataLine.Info(TargetDataLine.class,format);
TargetDataLine mic = (TargetDataLine) AudioSystem.getLine(micInfo);
mic.open(format);
System.out.println("Mic open.");
byte tmpBuff[] = new byte[mic.getBufferSize()/5];
mic.start();
while(outVoice) {
System.out.println("Reading from mic.");
int count = mic.read(tmpBuff,0,tmpBuff.length);
if (count > 0){
System.out.println("Writing buffer to server.");
out.write(tmpBuff, 0, count);
}
}
mic.drain();
mic.close();
System.out.println("Stopped listening from mic.");
}catch(Exception e){
e.printStackTrace();
}
}
}
public static void main (String args[]) throws IOException{
new ServerStream();
}
}
Client-server connection and subsequently Socket is based on the TCP protocol model.
As you can confirm in their docs.
What you seek is DatagramSocket based on UDP, you might suffer the loss of packages but that's the way things work. That's how streaming video works, you get some, you lose some.
Now, you question per se, one of the problems you have while implementing with a TCP protocol is that TCP is based on acknowledgements in order to keep the communications synchronized, if either your server or client fails to acknowledge then you might experience the stream to get stuck, because of that.

File cannot be deleted

Hi every one i'm programming a server client program which transfers file from client to server some files cannot be accepted and i should delete them after a test but the problem is file.delete() doesn't work for me cuz get an error that says file is open i java VM ;
package Serveur;
import java.io.DataInputStream;
import java.io.File;
import java.io.InputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.SQLException;
public class Serveur {
private static final int PORT =23456;
private ServerSocket serverSkt = null;
private Socket sock = null;
private FileOutputStream fos = null;
private boolean isStopped=false;
private InputStream fis;
private DataInputStream dis = null;
private int idUtil=0;
private String nomFichier = null;
private int taille = 0;
public Serveur() throws ClassNotFoundException, SQLException{
try {
serverSkt = new ServerSocket(PORT);
while(!isStopped){
sock=serverSkt.accept();
if(sock.isConnected()) {
fis=sock.getInputStream();
dis = new DataInputStream(fis);
idUtil=dis.readByte();
taille=dis.readInt();
nomFichier=dis.readUTF();
File fichier = new File("C:/Users/muddo/workspace/PFE/fichiers recu/"+nomFichier);
fos = new FileOutputStream(fichier);
byte[] bytes = new byte[taille];
int count=0;
while((count=dis.read(bytes)) > 0){
fos.write(bytes, 0, count);
}
dis.close();
fis.close();
fos.flush();
fos.close();
sock.close();
new max_allowed_packet();
String ext= fichier.getName().split("\\.")[1];
if(ext.equals("csv") || ext.equals("CSV") || ext.equals("Csv")){
TestCSV tc = new TestCSV(fichier.getAbsolutePath());
if(tc.test()==1){
new ChargerFichierCSV(fichier.getAbsolutePath());
}
else{
fichier.delete();
}
}
else {
new ChargerFichier(fichier.getAbsolutePath(),idUtil);
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void arreterServeur() throws IOException{
if(dis != null)
dis.close();
if(fis != null)
fis.close();
if(fos != null)
fos.close();
if(!sock.isClosed())
sock.close();
if(!serverSkt.isClosed())
serverSkt.close();
isStopped=true;
}
}
The server could be running with another user than the user than owns the file. Did you check file permissions??
File fichier = new File("C:/Users/muddo/workspace/PFE/fichiers recu/"+nomFichier);
The file is owned by user muddo and the server may be running in another user with less privileges. This seems like a bad idea. You should put shared files in a shared folder. Or give permissions to the server user.

Java - Sending byte array of MP3 file over TCP port and recieving

ok so im working on a program with a regular audio player gui but it has the option to take the song currently playing and convert it to a byte[] and send it to a client, where it will then be converted back into a mp3 file and played. not quite streaming but sorta live FTP. however, i can not seem to send the packets, and the reciever creates a blank mp3 file with size 0kb. nothing is being written, and idk why this happening. help pls.
import java.io.*;
import java.net.*;
import java.lang.*;
import java.util.*;
import javazoom.jl.player.*;
import org.apache.commons.io.IOUtils;
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Send {
public String address;
public int port;
public byte[] b;
public Send(String a, int p)
{
a = address;
p = port;
try
{
System.out.println("Server started");
System.out.println(b.length);
ServerSocket ss = new ServerSocket(2345);
Socket socket = ss.accept();
System.out.println("Waiting for client to connect...");
if(socket.isConnected())
{
System.out.println("Client connected");
}
OutputStream out = socket.getOutputStream();
DataOutputStream dos = new DataOutputStream(out);
if(b.length > 1)
{
dos.write(b);
dos.flush();
dos.close();
}
}catch(Exception e){}
}
}
and this is the reciever class, there is a whole gui that goes along with this but i wont add that junk unless you think it would help.
import java.io.*;
import java.net.*;
import java.lang.*;
import java.util.*;
import javazoom.jl.player.*;
import org.apache.commons.io.IOUtils;
public class Recieve {
String host = "localhost";
int port = 2345;
byte[] inFile;
public File file;
public static Socket socket;
public Recieve()
{
System.out.println("Waiting to connect to server..");
try
{
socket = new Socket(host,port);
if(socket.isConnected())
{
System.out.println("Connected to server on "+host+": "+port);
}
file = new File("H:\\Song.mp3");
InputStream is = socket.getInputStream();
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
int bytesRead = is.read(inFile, 0, inFile.length);
bos.write(inFile, 0, bytesRead);
bos.close();
FileOutputStream fop = new FileOutputStream(file);
fop.write(inFile);
fop.flush();
fop.close();
Playmusic play = new Playmusic(file);
Thread one = new Thread(play);
one.start();
if(file.length() < 2)
{
file.delete();
}
}catch(Exception e){System.out.println("ERROR ON STREAM "+e.getMessage());}
}
}

Java Socket - Sending files over sockets

I've been working on a Client/Server project and I'm stuck. I'm trying to write a back-up server so I can back-up my files to a remote computer. The problem is when I try to back-up my /home/user file, it gives me the following error on the server side:
java.io.UTFDataFormatException: malformed input around byte ...
I first send the size of the file, then I read the file into a byte array and then is send this byte array at once to the server, who receives it in a byte array it constructed using the file size. Is it a better solution to divide files into chunks or will the error remain?
This usually happens on a .zip file, but it doesn't always happen so that is why I'm confused. Can anyone help me out?
Code:
Server:
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
private ServerSocket server;
private Socket acceptingSocket;
public Server(int port){
try {
server = new ServerSocket(port);
} catch (IOException e) {
System.out.println("Try again");
}
}
public void run(){
BufferedInputStream buffer = null;
DataInputStream reader = null;
int size = 0;
try {
acceptingSocket = server.accept();
buffer = new BufferedInputStream(acceptingSocket.getInputStream());
reader = new DataInputStream(buffer);
size = reader.readInt();
} catch (IOException e1) {
}
System.out.println("Size: " + size);
for(int j = 0; j < size; j++){
try {
String path = reader.readUTF();
System.out.println("Path: " + path);
long length = reader.readLong();
System.out.println("Length: "+length);
boolean dir = reader.readBoolean();
System.out.println("Dir? " + dir);
path = "/backup" + path;
File file = new File(path);
if(!dir){
int t = file.getAbsolutePath().lastIndexOf("/");
String dirs = file.getAbsolutePath().substring(0, t);
File direcs = new File(dirs);
System.out.println(direcs.mkdirs());
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
byte[] b = new byte[(int) length];
int bytes = reader.read(b, 0, (int)length);
if(bytes != -1)
bos.write(b,0,(int)length);
BufferedOutputStream out = new BufferedOutputStream(acceptingSocket.getOutputStream());
DataOutputStream writer = new DataOutputStream(out);
writer.writeUTF("File " + file.getAbsolutePath() + " is created!");
writer.flush();
bos.close();
} else file.mkdirs();
} catch (IOException e) {
System.out.println(e);
}
}
}
public static void main(String[] args){
int port = Integer.parseInt(args[0]);
Server server = new Server(port);
while(true)
server.run();
}
}
Client:
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.util.ArrayList;
import java.util.concurrent.CopyOnWriteArrayList;
public class Client {
private DataInputStream serverToClient;
private Socket client;
private DataOutputStream clientToServer;
private String name;
public Client(String name, int port){
try {
client = new Socket(name, port);
//receive response server
serverToClient = new DataInputStream(client.getInputStream());
//send message to server
clientToServer = new DataOutputStream(client.getOutputStream());
this.name = name;
}
catch (IOException e) {
}
}
public void backUp(String filePath){
File file = new File(filePath);
CopyOnWriteArrayList<File> files = new CopyOnWriteArrayList<File>();
if(file.exists()){
try{
if(file.isDirectory()){
ArrayList<File> f = setToList(file.listFiles());
files.addAll(f);
for(File sendF : files){
if(sendF.isDirectory()){
files.addAll(setToList(sendF.listFiles()));
if(!setToList(sendF.listFiles()).isEmpty()) files.remove(sendF);
}
}
} else{
files.add(file);
}
clientToServer.writeInt(files.size());
for(File fi : files){
boolean dir = false;
if(fi.isDirectory()) dir = true;
clientToServer.writeUTF(fi.getAbsolutePath());
System.out.println(fi.getAbsolutePath());
long length = fi.length();
clientToServer.writeLong(length);
clientToServer.writeBoolean(dir);
System.out.println(length);
if(!dir){
FileInputStream fis = new FileInputStream(fi);
BufferedInputStream bis = new BufferedInputStream(fis);
byte[] buffer = new byte[(int)length];
bis.read(buffer, 0, (int)length);
clientToServer.write(buffer);
System.out.println(serverToClient.readUTF());
bis.close();
fis.close();
}
}
} catch(IOException e){
}
} else System.out.println("File doesn't exist");
}
private ArrayList<File> setToList(File[] listFiles) {
ArrayList<File> newFiles = new ArrayList<File>();
for(File lf : listFiles){
newFiles.add(lf);
}
return newFiles;
}
public static void main(String[] args){
String name = args[0];
int port = Integer.parseInt(args[1]);
System.out.println("Name: " + name + " Port: " + port);
Client client = new Client(name, port);
File file = new File(args[2]);
if(file.exists())client.backUp(args[2]);
else System.out.println("File doesn't exist");
}
}

Categories

Resources