hello please help me on this how to write on notepad....example
input your first name
input your last name
input your middle initial
input your address
input your age

this should be the ouput in notepad after inputting the data and this should be proper align .thanks in advance..hoping for your positive responds...

First name Last name m-initial address age

karl jackson S New York 24
michael maloon M California 25

You cannot write to note pad because notepad is an editor not a file. You need to write to a file. If you want to read that file using notepad then the file shoudend with .txt :

File file = new File("C:/path/fileName.txt");

I usually use BufferedWriter:

File file = new File("C:/path/fileName.txt");
BufferedWriter wr = new BufferedWriter(new FileWriter(file));

wr.write("Sometxt");
wr.newLine();
...
...

wr.close();

You will need to put the above inside a try - catch block.

Notepad might have an interface allowing you to insert text into its editor area from another process, but I don't know if it does and to be honest I doubt it.
It's a primitive application (by design, it's designed to be light weight and simple) after all.

>how to write on notepad?

Text from Java doc
Robot class : This class is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed. The primary purpose of Robot is to facilitate automated testing of Java platform implementations.

...
  try{
       Runtime.getRuntime().exec("notepad");
       Robot robot = new Robot();

       robot.delay(100);
       robot.keyPress(KeyEvent.VK_A);
       robot.keyPress(KeyEvent.VK_B);
       robot.keyPress(KeyEvent.VK_C);
      }catch(Exception ex) {}
    }
   ...

hi thanks for the reply..... what do you mean by the newline?

hello adatapost thanks for the reply i witl try this code....more power to you

I would write my output onto a normal text file with its extension .txt and this can easily be viewed using notepad just by clicking on the file


hello please help me on this how to write on notepad....example
input your first name
input your last name
input your middle initial
input your address
input your age

this should be the ouput in notepad after inputting the data and this should be proper align .thanks in advance..hoping for your positive responds...

First name Last name m-initial address age

karl jackson S New York 24
michael maloon M California 25

hello but how can i make this proper indented?that align to the header

hello ahm please help me the display is not in the proper column example
the first name Karl is not in the column of the first name then jackson is not in the column of the last name how can i make this in proper column..thanks in advance hoping for your positive responds.

what code are you using?

Jemz -

You can use PrintWriter's print(String) method in order to make sure your text ends up aligned properly. Since all that will be printed is the String that you supply, you can output whatever you want, followed by spaces, other text, whatever, and then when you want to go to the next line simply print the String "\n". Alternatively you could call PrintWriter's println method once, printing out everything that you want to be on the current line, and it will skip to the next line for you.

Of course, everything I said above also applies to the method JavaAddict showed you, except the class's methods he showed you are obviously different. Show us some code.

i use the br.write(String format("%-10",name);..this my code in writing...

but when i look in my file it is not properly align..help me please.

Is this correct?
String format("%-10",name)

Try to use System.out.println() and try to get the proper alignment and then when you are satisfied save it to the file

Try to read the API of the classes you are using in order to find what other methods you might use

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.