Results 1 to 2 of 2
- 03-26-2011, 03:42 PM #1
Member
- Join Date
- Nov 2010
- Location
- Beirut, Lebanon
- Posts
- 36
- Rep Power
- 0
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;
try
{
Scanner scan = new Scanner (new File("hardcode.txt"));
while(scan.hasNextLine())
{
num++;
scan.nextLine();
}
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";
}
Window.t.setText(str2);
}
catch (FileNotFoundException e)
{
System.out.println("file not found exception");
}
}
}
}
- 03-26-2011, 04:31 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Similar Threads
-
file opening in textarea
By Saran185 in forum AWT / SwingReplies: 2Last Post: 02-09-2011, 04:26 AM -
simple file output question thanks in advance
By farahm in forum New To JavaReplies: 5Last Post: 12-05-2010, 03:34 PM -
small java problem thanks in advance for your help
By farahm in forum Advanced JavaReplies: 6Last Post: 11-25-2010, 09:15 AM -
Add a jar file to Java load path at run time
By marioneil in forum Advanced JavaReplies: 5Last Post: 09-22-2010, 07:58 AM -
Displaying a file slected with a JFileChooser into a textarea
By happysal in forum AWT / SwingReplies: 1Last Post: 11-13-2008, 07:43 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks