Sinisterly
how to save a text and don't remove after reup a program. - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Java, JVM, & JRE (https://sinister.ly/Forum-Java-JVM-JRE)
+--- Thread: how to save a text and don't remove after reup a program. (/Thread-how-to-save-a-text-and-don-t-remove-after-reup-a-program)

Pages: 1 2


how to save a text and don't remove after reup a program. - Mr.Kurd - 07-31-2016

In The Name Of Allah
Salam Alekum
guys i maked tools.
I havd jtexField and and command.
I wany when i type any think jtextfield and i click on the command, save the text. When i close a program and i up it show me text in a textfield i mean don'r remove a text.
I hope you undetstanded me .


RE: how to save a text and don't remove after reup a program. - Ex094 - 07-31-2016

All you have to do is to read that text file when your program starts. Read the file and put the contents into the text box


RE: how to save a text and don't remove after reup a program. - Mr.Kurd - 07-31-2016

when i up a program i type for eg"Mr.Kurd" in a textField, i want when i click on command save it and when i close it and reup it showing me "Mr.Kurd" in the.textFild.


RE: how to save a text and don't remove after reup a program. - Ex094 - 07-31-2016

Let me clear what you want to say,
You have a TEXT BOX, and you have some text it in lets say MR. KURD, Now when I close that app and run it again, you want the textbox to have MR. KURD in it? Is that what you want?


RE: how to save a text and don't remove after reup a program. - Mr.Kurd - 07-31-2016

Yes Yes, You Are Really Really clever.


RE: how to save a text and don't remove after reup a program. - Ex094 - 07-31-2016

Tongue Then this is what you have to do

Code:
All you have to do is to read that text file when your program starts. Read the file and put the contents into the text box



RE: how to save a text and don't remove after reup a program. - Mr.Kurd - 07-31-2016

let's Say when i up a program nothink in TextBox, But i type Mr.Kurd and when i click save command save a Text for me & i wan't when i close it and reup it textBox content Mr.Kurd.


RE: how to save a text and don't remove after reup a program. - Ex094 - 07-31-2016

Create a function that would read the text file, now run that function when your program has initialized. You can put that function in the constructor of your application.


RE: how to save a text and don't remove after reup a program. - Mr.Kurd - 07-31-2016

Can write a code. Sorry i tired you.

i have new question how i use java with web service i :
GET
POST


RE: how to save a text and don't remove after reup a program. - Ex094 - 07-31-2016

It's the same that I gave you previously, https://docs.oracle.com/javase/tutorial/essential/io/file.html

Code:
try (BufferedReader reader = Files.newBufferedReader(file)) {
    String line = null;
    while ((line = reader.readLine()) != null) {
        JTextField.setText(line); //Put the text content in your text field
    }
} catch (IOException x) {
    System.err.format("IOException: %s%n", x);
}

This code assumes that you only have one line in the text file, you'll have to modify it if it is to contain more data