I'm trying to make a Client Server Application which the server list name of available images and the client select one of them to download Such as here :
Thread in Server
public void run()
{
try {
in = new DataInputStream (server.getInputStream());
out = new DataOutputStream(server.getOutputStream());
out.writeUTF("To List images write list");
out.writeUTF("To Exit write 2");
out.flush();
while((line = in.readUTF()) != null && !line.equals("2")) {
if(line.equalsIgnoreCase("list"))
{
String [] images= processor.listImages();
for ( int i=0;i<images.length;i++) {
out.writeUTF((+1)+"-"+images[i]);
out.flush();
line = "";
}
out.writeUTF("-1");
line = in.readUTF();
if(line.equalsIgnoreCase("2"))
{
break;
}else
{
BufferedImage img =processor.processInput(line);
boolean cc = ImageIO.write(img,"JPG",server.getOutputStream());
if(!cc)
{
out.writeUTF("The entered image is not avaliable !");
}else
{
System.out.println("Image Sent");
}
}
}else if(line.equalsIgnoreCase("2")){
break;
}
}
try{
in.close();
out.close();
server.close();
}catch(Exception e){
System.out.println("Error : "+ e.getMessage());
}
} catch (IOException e) {
System.out.println("IOException on socket listen: " + e.getMessage());
}
}
Client :
public void start() throws IOException
{
String line="";
while(true)
{
try{
line = inputFromStream.readUTF();
System.out.println(line);
line = inputFromStream.readUTF();
System.out.println(line);
line = readFromConsol.readLine();
writeToStream.writeUTF(line);
if(line.equalsIgnoreCase("2")){
break;
}else if(line.equalsIgnoreCase("list")){
boolean check=true;
while(check){
line = inputFromStream.readUTF();
System.out.println(line);
if("-1".equals(line)) {
check=false;
}
}
line = readFromConsol.readLine();
if(line.equalsIgnoreCase("2")) {
break;
}else
{
writeToStream.writeUTF(line);
BufferedImage img=ImageIO.read(
ImageIO.createImageInputStream(client.getInputStream()));
File f = new File("E:/MyFile.png");
f.createNewFile();
ImageIO.write(img, "PNG", f);
//process.saveImage(tmp);
System.out.println("Saved");
}
}
}catch(Exception e)
{
System.out.println(e);
break;
}
}
try{
inputFromStream.close();
readFromConsol.close();
writeToStream.close();
this.client.close();
}catch(Exception e){
System.out.println("Error : "+e.getMessage());
}
}
The problem is that all commands are successfully submitted till image receiving image stop there doesn't move
Try doing a flush of the outstream on the sending socket, then close the socket.
The problem appears to be that until the socket is flushed and closed the receiving IOImage.read() will wait thinking there are more images in the stream.
Related
I am trying to read and write shape objects to a file for a drawing program, but when I try to read from the file it shows that the file is empty. The file is definitely being written to and updated, but when trying to read from the file it is showing that there are zero bytes available. The shape class is serializable so I am not sure why this isn't working at all.
public void writeToFile() {
try {
FileOutputStream fileOut = new FileOutputStream("C:\\Users\\johnm\\eclipse-workspace\\CSE205_Assignment05\\save.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
for (Shape item : shapes) {
out.writeObject(item);
}
out.close();
fileOut.close();
System.out.println("Serialized data is saved in output.ser");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void loadFromFile() {
boolean cont = true;
Shape shape = null;
int count = 0;
while (cont) {
try {
FileInputStream fileIn = new FileInputStream("C:\\Users\\johnm\\eclipse-workspace\\CSE205_Assignment05\\save.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
System.out.println(in.available() + " Bytes");
if (in.available() != 0) {
shape = (Shape) in.readObject();
if (shape != null) {
shapes.add(shape);
count++;
} else {
System.out.println("Shape is null");
}
} else {
cont = false;
}
in.close();
fileIn.close();
System.out.println("Deserialized " + count + " Objects");
} catch (ClassNotFoundException c) {
System.out.println("Class not found");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Alright for some reason the .available() method isn't showing any bytes regardless of if there actually are any or not. To counter this I just threw in another try/catch statement where it continuously reads objects until it hits an EOFException and catches itself.
My code ended up looking like this once working.
public void loadFromFile() {
//** Loads set of shape objects from file
Shape shape = null;
int count = 0;
try {
FileInputStream fileIn = new FileInputStream("save.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
System.out.println(in.available() + " Bytes");
try {
while (true) {
shape = (Shape) in.readObject();
if (shape != null) {
shapes.add(shape);
count++;
} else {
System.out.println("Shape is null");
}
}
} catch (EOFException e) {
System.out.println("End of file exception");
}
in.close();
fileIn.close();
System.out.println("Deserialized " + count + " Objects");
repaint();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
I am trying to build a client server model in java using sockets to share files.
It works fine for one iteration of loop for sending a file but after that no data is received on the server. Please take a look at my code and suggest me something to correct this.
FileClient.java
public class FileClient {
private void listFiles() {
try {
DataInputStream dis = new DataInputStream(s.getInputStream());
while (dis.available() > 0) {
System.out.println(dis.readUTF());
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
private static void selectAndDownloadFiles() {
}
private Socket s;
public FileClient(String host, int port) {
try {
s = new Socket(host, port);
} catch (Exception e) {
e.printStackTrace();
}
}
public void sendFile(String file) throws IOException {
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
FileInputStream fis = new FileInputStream(file);
File myFile = new File (file);
dos.writeUTF(file);
dos.writeInt((int)myFile.length());
try {
sleep(2);
} catch (InterruptedException ex) {
Logger.getLogger(FileClient.class.getName()).log(Level.SEVERE, null, ex);
}
byte[] buffer = new byte[8192];
while (fis.read(buffer) > 0) {
dos.write(buffer);
}
}
public static void main(String[] args) {
int choice = 0;
Scanner in = new Scanner(System.in);
FileClient fc = new FileClient("localhost", 1988);
DataOutputStream dos = null;
try {
dos = new DataOutputStream(fc.s.getOutputStream());
} catch (IOException ex) {
Logger.getLogger(FileClient.class.getName()).log(Level.SEVERE, null, ex);
}
do {
try {
System.out.println("Choose an action to perform..!");
System.out.println("1. List the files..");
System.out.println("2. Select and download files");
System.out.println("3. Send a file..");
System.out.println("0. Exit..");
choice = in.nextInt();
String fileName;
switch (choice) {
case 1:
try {
dos.write(choice);
System.out.println("List Files Request Sent..!");
} catch (IOException ex) {
Logger.getLogger(FileClient.class.getName()).log(Level.SEVERE, null, ex);
}
sleep(2);
fc.listFiles();
break;
case 2:
selectAndDownloadFiles();
break;
case 3:
try {
dos.write(choice);
} catch (IOException ex) {
Logger.getLogger(FileClient.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("Enter file name to send");
fileName = in.next();
try {
fc.sendFile(fileName);
} catch (IOException ex) {
ex.printStackTrace();
}
break;
case 0:
System.exit(0);
break;
default:
System.out.println();
}
} catch (InterruptedException ex) {
Logger.getLogger(FileClient.class.getName()).log(Level.SEVERE, null, ex);
}
} while (choice != 0);
}
}
FileServer.java
public class FileServer extends Thread {
private static ServerSocket ss;
public FileServer(int port) {
try {
ss = new ServerSocket(port);
} catch (IOException e) {
e.printStackTrace();
}
}
public void run() {
File theDir = new File("C:\\Users\\Mehroz Irshad\\Desktop\\ServerFiles");
// if the directory does not exist, create it
if (!theDir.exists()) {
boolean result = false;
try {
theDir.mkdir();
result = true;
} catch (SecurityException se) {
//handle it
}
if (result) {
System.out.println("DIR created");
}
}
while (true) {
try {
Socket clientSock = ss.accept();
DataInputStream dis = new DataInputStream(clientSock.getInputStream());
DataOutputStream dos = new DataOutputStream(clientSock.getOutputStream());
int choice;
while ((choice = dis.read()) > 0) {
switch (choice) {
case 1:
System.out.println("List Files Request Received..!");
listFiles(clientSock);
System.out.println("List Files Response Sent..!");
break;
case 2:
sendSelectedFiles();
break;
case 3:
saveFile(clientSock);
break;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
private void saveFile(Socket clientSock) throws IOException {
DataInputStream dis = new DataInputStream(clientSock.getInputStream());
String fileName = dis.readUTF();
int filesize = dis.readInt();
FileOutputStream fos = new FileOutputStream("C:\\Users\\Mehroz Irshad\\Desktop\\ServerFiles\\" + fileName);
try {
sleep(2);
} catch (InterruptedException ex) {
Logger.getLogger(FileServer.class.getName()).log(Level.SEVERE, null, ex);
}
byte[] buffer = new byte[8192];
// Send file size in separate msg
int read = 0;
int totalRead = 0;
int remaining = filesize;
while ((read = dis.read(buffer, 0, Math.min(buffer.length, remaining))) > 0) {
totalRead += read;
remaining -= read;
System.out.println("read " + totalRead + " bytes.");
fos.write(buffer, 0, read);
}
//fos.close();
//dis.close();
}
public static void main(String[] args) {
FileServer fs = new FileServer(1988);
fs.start();
}
private void listFiles(Socket clientSock) {
File folder = new File("C:\\Users\\Mehroz Irshad\\Desktop\\ServerFiles");
File[] listOfFiles = folder.listFiles();
try {
DataOutputStream dos = new DataOutputStream(clientSock.getOutputStream());
if (listOfFiles.length > 0) {
for (int i = 0; i < listOfFiles.length; i++) {
dos.writeUTF(listOfFiles[i].getName());
}
} else {
dos.writeUTF("There are no files on the server..!");
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
private void sendSelectedFiles() {
}
}
Attached are the images of output.
I have written a multi-client TCP server that has the dual purpose of sending Json (text based) command strings and also sending an SQLite database file to multiple clients. Everything is working nicely except... the database file uses the special character hex81 (decimal 129) for some internal purpose. When I read the database file into a byte array, Java converts this character to decimal -127 because of Java's signed representation of bytes. However the socket is actually transmitting this character as hex3F. So when I receive the save the data in the client and save it to a file, the database is corrupt due to the presence of h3F chars instead of h81.
Why is this happening and how do I correct it?
Here is the complete code that I am using for the server (a new instance of this class is started by a separate TCPServer class whenever a client connects):
public class TCPServerThread extends Thread {
// Connect status constants
private final static int NULL = 0;
private final static int DISCONNECTED = 1;
private final static int DISCONNECTING = 2;
private final static int BEGIN_CONNECT = 3;
private final static int CONNECTED = 4;
private final static String END_SESSION = new Character((char)0).toString(); // Indicates the end of a session
// Connection state info
private int connectionStatus = DISCONNECTED;
private static StringBuffer txBuffer = new StringBuffer("");
private static ByteArrayOutputStream txBuffer2 = new ByteArrayOutputStream();
private static File file;
// TCP Components
private ServerSocket serverSocket = null;
private Socket clientSocket = null;
private BufferedReader in = null;
private PrintWriter out = null;
private DataOutputStream out2 = null;
private String s = "";
private DecodeJson dj = new DecodeJson();
private boolean doRun;
public TCPServerThread(Socket socket) throws IOException {
doRun = true;
clientSocket = socket;
changeStatusTS(BEGIN_CONNECT, true);
}
public void run() {
while (doRun) {
try { // run every ~10 ms
Thread.sleep(10);
}
catch (InterruptedException e) {}
if (Mainscreen.shutdown == true || TCPClient.close == true)
connectionStatus = DISCONNECTING;
switch (connectionStatus) {
case BEGIN_CONNECT:
try {
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
out = new PrintWriter(clientSocket.getOutputStream(), true);
out2 = new DataOutputStream(clientSocket.getOutputStream());
TCPServer.writers.add(out); // add this socket to the connected clients list
changeStatusTS(CONNECTED, true);
}
// If error, clean up and output an error message
catch (IOException e) {
cleanUp();
changeStatusTS(DISCONNECTED, false);
}
break;
case CONNECTED:
try {
// Send data
if (txBuffer.length() != 0) {
for (PrintWriter writer : TCPServer.writers) {
writer.print(txBuffer);
writer.flush();
if(writer.checkError()) {
closeSocket();
changeStatusTS(DISCONNECTING, true);
}else {
changeStatusTS(NULL, true);
}
}
txBuffer.setLength(0);
}
if (txBuffer2.size() != 0) {
byte[] result = txBuffer2.toByteArray();
System.out.println(result[745] + "," + result[746] + "," + result[747] + "," + result[748] + "," + result[749] + "," + result[750]);
out2.write(result);
out2.flush();
txBuffer2.reset();
}
// Receive data
if (in.ready()) {
s = in.readLine();
if ((s != null) && (s.length() != 0)) {
// Check if it is the end of a transmission
if (s.equals(END_SESSION)) {
changeStatusTS(DISCONNECTING, true);
}
// Otherwise, receive text
else {
dj.receiveString(s);
changeStatusTS(NULL, true);
}
}
}
}
catch (IOException e) {
System.out.println("Socket error " + e);
cleanUp();
changeStatusTS(DISCONNECTED, false);
}
break;
case DISCONNECTING:
// Tell clients to disconnect as well
if (out != null) {
out.print(END_SESSION);
out.flush();
}
// Clean up (close all streams/sockets)
cleanUp();
changeStatusTS(DISCONNECTED, true);
break;
default: break;
}
}
}
// Add command to text send-buffer
public static void sendString(String s) {
synchronized (txBuffer) {
txBuffer.append(s + "\n");
}
}
// Add file data to binary send buffer
public static void sendFile(String filename) {
synchronized (txBuffer2) {
file = new File(filename);
byte[] content = new byte[(int)file.length()];
FileInputStream fin;
try {
fin = new FileInputStream(file);
fin.read(content);
System.out.println(content[745] + "," + content[746] + "," +content[747] + "," +content[748] + "," + content[749] + "," + content[750]);
txBuffer2.write(content);
fin.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException f) {
f.printStackTrace();
}
}
}
private void changeStatusTS(int newConnectStatus, boolean noError) {
// Change state if valid state
if (newConnectStatus != NULL) {
connectionStatus = newConnectStatus;
}
}
private void closeSocket(){
try {
if (clientSocket != null) {
clientSocket.close();
clientSocket = null;
}
}
catch (IOException e) { clientSocket = null; }
}
// Cleanup for disconnect
private void cleanUp() {
try {
if (serverSocket != null) {
serverSocket.close();
serverSocket = null;
}
}
catch (IOException e) { serverSocket = null; }
try {
if (clientSocket != null) {
clientSocket.close();
clientSocket = null;
}
}
catch (IOException e) { clientSocket = null; }
try {
if (in != null) {
in.close();
in = null;
}
}
catch (IOException e) { in = null; }
if (out != null) {
TCPServer.writers.remove(out); // remove this socket for the connected sockets list
out.close();
out = null;
}
doRun = false;
}
}
So as EJP suggested, the problem is due to using readers and writers.
The following code now works as expected (thanks for the tip EJP). I will get around to addressing the issue raised by VGR about wrapping client.getOutputStream() in both a PrintWriter and a BufferedOutputStream, but for now the code works nicely (this is a work in progress).
public class TCPServerThread extends Thread {
// Connect status constants
private final static int NULL = 0;
private final static int DISCONNECTED = 1;
private final static int DISCONNECTING = 2;
private final static int BEGIN_CONNECT = 3;
private final static int CONNECTED = 4;
private final static String END_SESSION = new Character((char)0).toString(); // Indicates the end of a session
// Connection state info
private int connectionStatus = DISCONNECTED;
private static StringBuffer txBuffer = new StringBuffer("");
private static BufferedOutputStream out2 = null;
private static File file;
// TCP Components
private ServerSocket serverSocket = null;
private Socket clientSocket = null;
private BufferedReader in = null;
private PrintWriter out = null;
private static BufferedInputStream fileData = null;
private String s = "";
private DecodeJson dj = new DecodeJson();
private boolean doRun;
public TCPServerThread(Socket socket) throws IOException {
doRun = true;
clientSocket = socket;
changeStatusTS(BEGIN_CONNECT, true);
}
public void run() {
while (doRun) {
try { // run every ~10 ms
Thread.sleep(10);
}
catch (InterruptedException e) {}
if (Mainscreen.shutdown == true || TCPClient.close == true)
connectionStatus = DISCONNECTING;
switch (connectionStatus) {
case BEGIN_CONNECT:
try {
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
out = new PrintWriter(clientSocket.getOutputStream(), true);
out2 = new BufferedOutputStream(clientSocket.getOutputStream());
TCPServer.writers.add(out); // add this socket to the connected clients list
changeStatusTS(CONNECTED, true);
}
// If error, clean up and output an error message
catch (IOException e) {
cleanUp();
changeStatusTS(DISCONNECTED, false);
}
break;
case CONNECTED:
try {
// Send data
if (txBuffer.length() != 0) {
for (PrintWriter writer : TCPServer.writers) {
writer.print(txBuffer);
writer.flush();
if(writer.checkError()) {
closeSocket();
changeStatusTS(DISCONNECTING, true);
}else {
changeStatusTS(NULL, true);
}
}
txBuffer.setLength(0);
}
if (fileData != null) {
byte[] buffer = new byte[(int) file.length()];
for (int read = fileData.read(buffer); read >=0; read = fileData.read(buffer)) out2.write(buffer, 0, read);
out2.flush();
fileData = null;
}
// Receive data
if (in.ready()) {
s = in.readLine();
if ((s != null) && (s.length() != 0)) {
// Check if it is the end of a transmission
if (s.equals(END_SESSION)) {
changeStatusTS(DISCONNECTING, true);
}
// Otherwise, receive text
else {
dj.receiveString(s);
changeStatusTS(NULL, true);
}
}
}
}
catch (IOException e) {
System.out.println("Socket error " + e);
cleanUp();
changeStatusTS(DISCONNECTED, false);
}
break;
case DISCONNECTING:
// Tell clients to disconnect as well
if (out != null) {
out.print(END_SESSION);
out.flush();
}
// Clean up (close all streams/sockets)
cleanUp();
changeStatusTS(DISCONNECTED, true);
break;
default: break;
}
}
}
// Add command to text send-buffer
public static void sendString(String s) {
synchronized (txBuffer) {
txBuffer.append(s + "\n");
}
}
// Add file data to binary send buffer
public static void sendFile(String filename) {
file = new File(filename);
try {
fileData = new BufferedInputStream(new FileInputStream(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
private void changeStatusTS(int newConnectStatus, boolean noError) {
// Change state if valid state
if (newConnectStatus != NULL) {
connectionStatus = newConnectStatus;
}
}
private void closeSocket(){
try {
if (clientSocket != null) {
clientSocket.close();
clientSocket = null;
}
}
catch (IOException e) { clientSocket = null; }
}
// Cleanup for disconnect
private void cleanUp() {
try {
if (serverSocket != null) {
serverSocket.close();
serverSocket = null;
}
}
catch (IOException e) { serverSocket = null; }
try {
if (clientSocket != null) {
clientSocket.close();
clientSocket = null;
}
}
catch (IOException e) { clientSocket = null; }
try {
if (in != null) {
in.close();
in = null;
}
}
catch (IOException e) { in = null; }
if (out != null) {
TCPServer.writers.remove(out); // remove this socket for the connected sockets list
out.close();
out = null;
}
doRun = false;
}
}
I am collecting data from Android App(Accelerometer and Gyro) and send it to Desktop app via Java Socket but in high rates
(SENSOR_DELAY_FASTEST,SENSOR_DELAY_GAME)
Notes :
readingsList : contains all reading from sensors
I remove from list the data being sent to server
Only data sent once and i made sure it's ordered from client side
but i got them unordered in server side ( I received all data but not ordered)
processData(String reading) function may takes time but not too much
Client Code :
class SocketClientThread implements Runnable {
public SocketClientThread(){
}
public void run() {
while (!Thread.currentThread().isInterrupted() && breathingStarted) {
try {
InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
socket = new Socket(serverAddr, SERVERPORT);
PrintWriter out =
new PrintWriter(socket.getOutputStream(), true);
socket.setSendBufferSize(Integer.MAX_VALUE);
socket.setReceiveBufferSize(Integer.MAX_VALUE);
int lastCount = readingsList.size();
out.println(readingsList);
out.flush();
out.close();
int toberemoved = lastCount;
if(readingsList.size() > 0){
for (int i = 0; i < toberemoved; i++) {
readingsList.remove(0);
}
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
Server Code :
serverSocket = new ServerSocket(port);
serverSocket.setSoTimeout(minutes*60*1000);
Thread thread = new Thread() {
public void run() {
while(!isStopped)
{
try
{
Socket connection = serverSocket.accept();
connection.setReceiveBufferSize(Integer.MAX_VALUE);
connection.setSendBufferSize(Integer.MAX_VALUE);
BufferedReader input =
new BufferedReader(new InputStreamReader(connection.getInputStream()));
PrintWriter out =
new PrintWriter(connection.getOutputStream(), true);
String inputLine;
while ((inputLine = input.readLine()) != null) {
recentReading = inputLine;
String oldReading = recentReading;
String modifiedReading = oldReading.replace("[", "");
modifiedReading = modifiedReading.replace("]", "");
String [] readings = modifiedReading.split(",");
for (int i = 0; i < readings.length; i++) {
String currentReading = readings[i].trim();
String [] tokens = currentReading.split("_");
processData(currentReading);
}
}
}catch(SocketTimeoutException s)
{
System.out.println("Socket timed out!");
display.syncExec(new Runnable() {
public void run() {
statusVal.setText("Socket timed out!");
}
});
break;
}catch(SocketException s)
{
if(serverSocket.isClosed()){
display.syncExec(new Runnable() {
public void run() {
statusVal.setText("Disconnected");
}
});
}
break;
}catch(IOException e)
{
e.printStackTrace();
break;
}
}
}
};
thread.setDaemon(true);
thread.start();
I am getting data after it's time (not ordered)
I have a writing/reading .txt files program, which I will put at the bottom so I can ask my question first: Usually, if I have the file open and run the program, I need to close the .txt file and reopen it in order to see the changes the program makes. Is there a way to refresh the document in the program so that It will change before my eyes in real time? Here is the program:
package SingleThings;
import java.io.*;
public class TextUtil {
public String path;
public String[] lines;
public TextUtil(String pathy,int length){
path=pathy;
makeFile();
lines = new String[length];
for(int i = 0;i<length;i++){
lines[i]=getLine(i+1);
}
}
public void clear(){
try{
FileWriter write = new FileWriter(path , false);
}catch(IOException e){
System.out.println("There was a problem oh noesss " + e);
}
}
private void makeFile(){
try {
File file = new File(path);
if (file.createNewFile()){
System.out.println("Creating file...");
}else{
System.out.println("Loading file...");
}
} catch (IOException e) {
e.printStackTrace();
}
}
public String getLine(int line){
BufferedReader in;
String read = null;
int linenum = line;
try {
in = new BufferedReader(new FileReader(path));
while(linenum > 0){
read = in.readLine();
linenum--;
}
in.close();
return read;
}catch(IOException e){
System.out.println("There was a problem:" + e);
return "error";
}
}
private void write(String text){
BufferedWriter out;
try {
out = new BufferedWriter(new FileWriter(path,true));
out.write(text);
out.newLine();
out.close();
}catch(IOException e){
System.out.println("There was a problem:" + e);
}
}
public void update(){
clear();
for(int i=0;i<lines.length;i++){
if(lines[i]!=null){
write(lines[i]);
}else{
write("");
}
}
}
}