Results 1 to 2 of 2
  1. #1
    farahm is offline Member
    Join Date
    Nov 2010
    Beirut, Lebanon
    Rep Power

    Default java load file to textarea, thanks in advance

    ok so the program has a load button that loads from a file to the test area(t).
    now the problem is if i use the below code their is an extra empty line between each new line and if i take out the "\n" then the lines will all be loaded on one line
    any help?
    public class MyActionListener3 implements ActionListener
    public void actionPerformed(ActionEvent event)
    if(event.getSource()== Window.button3)
    int num=0;
    String str="";
    String str2="";
    int temp=0;
    Scanner scan = new Scanner (new File("hardcode.txt"));
    Scanner scan2 = new Scanner (new File("hardcode.txt"));
    for(int i=0;i<num;i++)
    str += scan2.nextLine();
    Scanner scan3 = new Scanner (new File("hardcode.txt"));
    for(int i=0;i<num;i++)
    String s1 = scan3.nextLine();
    int length = s1.length();
    String line1 = str.substring(0+(temp),temp+length);
    temp += length;
    str2 += line1+"\n";
    catch (FileNotFoundException e)
    System.out.println("file not found exception");

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Rep Power


    After 25 postings you should know by now how to use the "code tags" so that any code you post retains its original formatting.

    To answer your questions just use the read(...) method of a JTextArea.

Similar Threads

  1. file opening in textarea
    By Saran185 in forum AWT / Swing
    Replies: 2
    Last Post: 02-09-2011, 04:26 AM
  2. simple file output question thanks in advance
    By farahm in forum New To Java
    Replies: 5
    Last Post: 12-05-2010, 03:34 PM
  3. small java problem thanks in advance for your help
    By farahm in forum Advanced Java
    Replies: 6
    Last Post: 11-25-2010, 09:15 AM
  4. Add a jar file to Java load path at run time
    By marioneil in forum Advanced Java
    Replies: 5
    Last Post: 09-22-2010, 07:58 AM
  5. Replies: 1
    Last Post: 11-13-2008, 07:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts