Displaying a .txt file in a TextArea...
hello everyone, i was wondering if you could help me with a problem i have.
basically, i have to type a word in a TextField that corresponds to a filename. i.e. type in 'results' and that will correspond to a file called 'results.txt'. once i type in this word, i click a button and this will open the file 'results.txt' into a TextArea below.
I have been working on this for several days now. I can figure out how to open the file into the TextArea, but it displays the file in there straight away. I need to make it so that the button has to be pressed first and then displays it.
It also needs to be able to do more than just one file. I have several files in a folder and depending on what i type in the TextField depends on which file is displayed.
I would appreciate ANY help at all on this as I am struggling quite alot.
Thnk you in advance
Troy
below is what i have so far, but it has one error. Could u help me with that?
import java.awt.*;
import javax.swing.*;
import java.io.*;
public class NorthPanel extends JPanel
JTextArea instruct;
String str;
BufferedReader br;
public NorthPanel()
setBackground(Color.white);
instruct = new JTextArea(5,60);
instruct.setLayout(new FlowLayout(FlowLayout.CENTER));
instruct.setBorder(BorderFactory.createTitledBorder("Java Work"));
instruct.setLineWrap(true);
instruct.setWrapStyleWord(true);
instruct.setEditable(false);
readFileIntoTextArea();
add(instruct);
private void readFileIntoTextArea()
try {
File f = new File("readme.txt");
br = new BufferedReader (new FileReader(f));
while ((str = br.readLine()) != null)
instruct.append(str);
}
Similar Messages
-
Displaying a .txt file in a JTextArea
hello everyone, i was wondering if you could help me with a problem i have.
basically, i have to type a word in a TextField that corresponds to a filename. i.e. type in 'results' and that will correspond to a file called 'results.txt'. once i type in this word, i click a button and this will open the file 'results.txt' into a TextArea below.
I have been working on this for several days now. I can figure out how to open the file into the TextArea, but it displays the file in there straight away. I need to make it so that the button has to be pressed first and then displays it.
It also needs to be able to do more than just one file. I have several files in a folder and depending on what i type in the TextField depends on which file is displayed.
I would appreciate ANY help at all on this as I am struggling quite alot.
Thnk you in advance
Troycorrect me if it is a misunderstanding, but why don't you open the file (read in the content of a file in f.e. String text) , then you do a setText(text) ?
in order to find out what was typed in you can choose getText()
so far,
stefan gross -
Work around to display large .txt files in Nanos?
I'd like to read a large .txt file on a Nano...breaking the .txt file into 4k increments isn't feasible.
Anyone know how to display a large .txt file on a Nano's screen -- from the Notes folder, or, elsewhere?
Thanks!Hmmmm. Not so sure about that one.
Actually, it might be worth checking through the iPod + iTunesdownloads page to see if there are any useful widgets and whatnot for that there. (There's a few notes-related items showing up there too, which might work better than my suggestions about performing unnatural acts with your lyrics tags.)
http://www.apple.com/downloads/macosx/ipod_itunes/ -
Displaying doc/txt file contents from portlet
Hi, Can someone pls give a hint on how to do this:
One "book" type content created, with a doc file uploaded. The "publisher " for
this content is set to "sams".
create a content selector which retrieves only this (content) book correctly.
create two portlets. one portlet with above content selector inserted, displays
the publisher name with a hyperlink.
I want the other portlet to display the contents of the file uploaded, for this
publisher. I could establish portlet comm. and could display other properties
of the book such as "author/titile" on the second portlet, but want to know how
to display the uploaded file contents.
thanks much,
-developerAs far as retriving the contents of an uploaded file...
If your XML document has been loaded into Content Management as a binary
property, you have two options:
a) to directly inline the content into the JSP, do something like this:
<cm:getProperty id="node" name="binaryPropertyName" failOnError="true"
isMultiple="false"/>
(This assumes node holds a reference to the Content Management Node
object (perhaps retrieved via a <cm:getNode> tag)
b) to retrieve the value into a script variable for more processing, do
something like this:
<%
Property bodyProp= (Property)node.getProperty("binaryPropertyName");
InputStream in= node.getPropertyBytes( bodyProp.getId() );
// dont forget to close the InputStream
String result=null;
InputStreamReader reader= new InputStreamReader(in);
StringBuffer streamContents= new StringBuffer();
char[] data= new char[8192];
int charsRead;
while ((charsRead = reader.read(data)) > 0 )
streamContents.append(data, 0, charsRead);
result= streamContents.toString();
%>
-Steve
"portal developer" <[email protected]> wrote in message
news:40ae343d$[email protected]..
>
Hi, Can someone pls give a hint on how to do this:
One "book" type content created, with a doc file uploaded. The "publisher" for
this content is set to "sams".
create a content selector which retrieves only this (content) bookcorrectly.
>
create two portlets. one portlet with above content selector inserted,displays
the publisher name with a hyperlink.
I want the other portlet to display the contents of the file uploaded,for this
publisher. I could establish portlet comm. and could display otherproperties
of the book such as "author/titile" on the second portlet, but want toknow how
to display the uploaded file contents.
thanks much,
-developer -
How to display a .txt file?
i would like to ask if JAVA can open and display a text file by issuing a command from my application
is it possible to do it without using a JEditorPane?
something else too, how can i set the background for my application to be a .jpg image?
i searched and realised there is no such method as
setBackground(String url)Try this... Note you need to add adequate exception trapping and detect special cases like the file being larger than the allocatable size of a character array (in which case you can't convert the file to a string and will need to 'display' the file in sections)...
import java.io.*;
public class LoadFile {
public static String fileToString(File file) throws IOException {
char[] fileContents = new char[(int) file.length()];
FileReader fr = new FileReader(file);
if(fr.read(fileContents) != fileContents.length) {
System.err.println("There was a problem reading the file contents");
return null;
else return new String(fileContents);
public static void main(String[] args) throws IOException {
if(args.length != 1) System.err.println("Usage:\n\tjava LoadFile <filename>");
else {
File f = new File(args[0]);
try {
String s = fileToString(f);
System.out.println(s);
} catch(IOException e) {
System.err.println("Whoops");
}Hope that helps... -
Attached txt file is displayed with sapoffice intead of notepad
Hi,
i´ve developed a bsp page that uploads files using fm SO_DOCUMENT_INSERT_API1.
When i try to display a txt file uploaded as above explained (with transaction FB03) the document is displayed with sapoffice and not with notepad as i expected.
Why is this hapenning?
What do i have to do so that a txt file is opened with notepad?
i´m able to upload a pdf and display it afterwards in fb03 with acrobat reader.
i´m able to upload a doc and display it afterwards in fb03 with msword.
but with a txt file it does not work.
Best regards.
Edited by: Pablo Casamayor on Nov 19, 2011 12:02 PMYou should be doing something like this to open a text file in Notepad:
Message Edited by smercurio_fc on 09-12-2007 01:07 PM
Attachments:
Example_BD.png 2 KB -
Output Not Appearing in Exported .TXT File
Hi
I am using Crystal Reports XI R2, using Universe as a Data source, and Business Objects XI Release 2.Oracle 10G as a Datasource with Universe.
I am getting Correct Data, in Crystal Report Viewer, But if i am making attempt to Export the Data to a .TXT File, it is not displaying tha Data as in Crystal Report Viewer.
1) In my Case we are Using Page Number Reset Option, which is working fine in Crystal Reports Viewer, but in .TXT file output, Page Number is not reseted.
2) We are Using Group Headers which has Text Objects and Formula Field, the Group Header Displays for Each Group in Viewer, but same is not displayed in .TXT File output.
3) For Very First Group, In Viewer it Displaying Page No as 1,1,2,3.....(which is not Correct, it should be 1,2,3....), but in .TXT file Output, it Displays right One as 1,2,3......
But If iam Exporting the Report to an PDF File, it Displays Eactly as what is in viewer.
So Kindly Help me on this Issue.
Thanks
M.Mukesh
Edited by: m.mukesh on Dec 9, 2010 9:49 PM
Edited by: m.mukesh on Dec 9, 2010 9:50 PMMoved to BOE Admin forum
-
Opening an *.txt file in oracle forms 4.5
I am facing this problem I want to call an text file from a certain location and display the same when an user hits a particular button which has to be done in Oracle Forms 4.5.
Could u pls help meIf you want to display the *.txt file use ole object to do that and if you want to read the data from the text file and display in the text field then use textio package.
Hope this helps you.
Regards
Gaurav -
I have a VI and an attched .txt data file. Now I want to read the data from the .txt file and display it as an array in the front panel. But the result is not right. Any help?
Attachments:
try2.txt 2 KB
read_array.vi 21 KBThe problem is in the delimiters in your text file. By default, Read From Spreadsheet File.vi expects a tab delimited file. You can specify a delimiter (like a space), but Read From Spreadsheet File.vi has a problem with repeated delimiters: if you specify a single space as a delimiter and Read From Spreadsheet File.vi finds two spaces back-to-back, it stops reading that line. Your file (as I got it from your earlier post) is delimited by 4 spaces.
Here are some of your choices to fix your problem.
1. Change the source file to a tab delimited file. Your VI will then run as is.
2. Change the source file to be delimited by a single space (rather than 4), then wire a string constant containing one space to the delimiter input of Read From Spreadsheet File.vi.
3. Wire a string constant containing 4 spaces to the delimiter input of Read From Spreadsheet File.vi. Then your text file will run as is.
Depending on where your text file comes from (see more comments below), I'd vote for choice 1: a tab delimited text file. It's the most common text output of spreadsheet programs.
Comments for choices 1 and 2: Where does the text file come from? Is it automatically generated or manually generated? Will it be generated multiple times or just once? If it's manually generated or generated just once, you can use any text editor to change 4 spaces to a tab or to a single space. Note: if you want to change it to a tab delimited file, you can't enter a tab directly into a box in the search & replace dialog of many programs like notepad, but you can do a cut and paste. Before you start your search and replace (just in the text window of the editor), press tab. A tab character will be entered. Press Shift-LeftArrow (not Backspace) to highlight the tab character. Press Ctrl-X to cut the tab character. Start your search and replace (Ctrl-H in notepad in Windows 2000). Click into the Find What box. Enter four spaces. Click into the Replace With box. Press Ctrl-V to paste the tab character. And another thing: older versions of notepad don't have search and replace. Use any editor or word processor that does. -
Want to display a space after last field in the output txt file
hi
I want to display a space after last field in the output txt file which is generaed by my program on utility server the last field lengyt we have defined is four and in database it is of three characters and requirement is to disppaly the last fourth field as space in the output file w hich is not shown as the txt file automatically gets closed at the third place as it is the last field in the record and ind atabase records are of therss char only but user wants to display this fourth position in the notepad output file as space ( which is last field in the output file)
eg
name house street country
record output coming in file
ram h3 street3 thn now this thn which is last field the notepad get closed at thn only
i want to display one space in last field for the whole of output file
ie ram h3 street3 thn(space)
sham h4 street4 sgp(space) so on......
we need to show this space in the output file as blank
regards
Arorahi Atish
i am using
loop at gt_sagadr_outtab into wa_sagadr_outtab
move wa_sagadr_outtab-country to wa_sagadr_text+223(226).
endloop
in this last field ie country i need to display the last 226 as blank as only country key is two char in database so the last space is not shown
i am not unsing the fM as tolb by you
and afterwards
i am usning
Concatenate 'Sagadr_' sy-datum sy-uzeit '.dat' into gv_filename_sagadr.
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
CLIENT = SY-MANDT
LOGICAL_FILENAME = gc_lfile
OPERATING_SYSTEM = SY-OPSYS
PARAMETER_1 = gc_param1
PARAMETER_2 = gc_send
PARAMETER_3 = gv_filename_sagadr
USE_PRESENTATION_SERVER = ' '
WITH_FILE_EXTENSION = ' '
USE_BUFFER = ' '
ELEMINATE_BLANKS = 'X'
IMPORTING
EMERGENCY_FLAG =
FILE_FORMAT =
FILE_NAME = gv_filepath_sagadr
EXCEPTIONS
FILE_NOT_FOUND = 1
OTHERS = 2
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
and lastly
open dataset gv_filepath_sagadr for output in text mode encoding default.
if sy-subrc eq 0.
loop at gt_sagadr_text into wa_sagadr_text.
transfer wa_sagadr_text to gv_filepath_sagadr.
endloop.
endif.
close dataset gv_filepath_sagadr.
if sy-subrc = 0.
message S002 with gv_filepath_sagadr. "Files & created on Application server
endif.
SO NOT SURE WHERE TO USE THE CODE AND HOW -
Reading .txt files and put it into a TextArea
Hi all,
I got a problem! I have to make something like a messenger.
I want to put the written text into a .txt file, after that I have to get the text out of the .txt file and put in into a TextArea.
I would ike it to to that like this:
">User 1
Hello!
>User 2
Hi!
Now here are my questions:
1: What is the moet easy way to do this ?
2: How could i put Enters into a .txt file with Java ?
3: How could i read all the text from the .txt file and put it into a TextArea WITH ENTERS ?
Thanks for your help!
Greetings, Jasper Kouwenberguse JTextArea.read(new FileReader(fileName)) for reading.
and JTextArea.write(new FileWriter(fileName)) for writing.
The enters should be ok if the user press enter and adds a new line ("\n") to the text area component.
It will save the enter in the text file and load it correctly back to the text area.
If you want to add enter programmatically just add "\n" string to the text area component. -
Read numbers from a .txt file and display them in a graph
How can I get Labview 7 to read from a txt. file containing a lot of
coloumns with different datas? There`s only two of the coloumns that are
interesting to me, the first, that contains the time of the measuring, and
one in the middle, that contains the measured temperatures. I want Labview
to read this datas and display them graphicly.
Thanks from StaleHere's one way.
You can also use the help-> find examples and search for "text".
2006 Ultimate LabVIEW G-eek.
Attachments:
Graph.vi 21 KB -
How to get Text from (.txt) file to display in the JTextArea ?
How to get Text from (.txt) file to display in the JTextArea ?
is there any code please tell me i am begginer and trying to get data from a text file to display in the JTextArea /... please help...public static void readText() {
try {
File testFile = new File(WorkingDirectory + "ctrlFile.txt");
if (testFile.exists()){
BufferedReader br = new BufferedReader(new FileReader("ctrlFile.txt"));
String s = br.readLine();
while (s != null) {
System.out.println(s);
s = br.readLine();
br.close();
catch (IOException ex){ex.printStackTrace();}
}rykk -
How to display Japanese fonts in a .txt file i received?
I received an email attachment that is a .txt file.
Some of it is in Japanese and some is in English.
The Japanese text turns out to look like gibberish.... like this...
Media Start Media End Duration Log Note
01:17:12;18 01:17:20;26 00:00:08;09 DZÇÍÇÁÇÃÉCÉìÉåÉbÉgÇÇøÇÂÇ¡Ç∆âÒǡǃÇ≥ÅAÇ¢ÇÎÇÒÇ»É]Å[ÉìÇ÷ǢǡǃǛǃÇsÇÖÇíÇíÇÅÇâÇéÇ ÷LJǡÇ∆ãflÇ≠çsǡǃÇ≥ÅAÉwÉäÇÃñ≥ë éûä‘Çè≠Ç»Ç≠Ç∑ÇÈÅB
01:17:25;21 01:17:30;21 00:00:05;01 â¥ÇÁÇ©ÇÁ3ÉÅÅ[É^Å[ÇÃÇ∆DZÇÎÇ≈äCÇ™ÉAÉâÉCÉîDžǻǡÇΩÇÊÅI
01:17:32;10 01:17:36;20 00:00:04;11 ÉwÉäǙdžÇÈÅBëDǙdžÇÈÅBå„âΩÇ™ó~ǵǢÅH
If i send this cut/paste back to the person who emailed it to me, they say it is displaying fine in Japanese.
I have no idea how to make this text show up in Japanese.
Thanks for any help.
BrianYou might try giving the file a ".txt" extension. Then drag it on top of your Safari icon in the dock, which should open it with Safari. Then, under "View", select a Japanese "Text Encoding". My guess is that this is Shift-JIS.
I am assuming you have not removed Japanese fonts from your system. -
Configure DW CC to display .txt files like .cfm files
Earlier DW versions allowed the user to edit the MMDocumentTypes.xml and Extensions.txt files to customize the color coding of file types. On DW CC 13.2 I'm trying to display .txt files in Code View identical to .cfm files, but editing MMDocumentTypes.xml and Extensions.txt no longer seems to have any effect. Here's the app note that used to work...
http://kb2.adobe.com/cps/164/tn_16410.html
What am I doing wrong?I'm having this same issue trying to view .inc files in split view using DW CC 2014.1.
I've never had issues on other versions of DW after editing the MMDocumentTypes.xml file
Maybe you are looking for
-
Can I move just music to an external hard drive?
I'm trying to set up our home network so that everyone can access our large music library through a hard drive attached to apple extreme, but manage all of their other iTunes media files (apps, podcasts, etc) on their own devices. Is it possible for
-
How to get or set default fiscal year value in billing doc
Hi All, my question is simple, how to get or set default fiscal year value (VBRK_GJAHR) in billing document.. is it possible. Thanks. Regards, Michael
-
To Create an XML from a java Bean
I have a java class( a bean ) wih a number of properties. I need to create an xml file which is closely tied with the bean. How can I do it?
-
Hi friends, My per diem requirements are as below: Example scenario: Travel from Singapore >Bangkok>Japan>Singapore Employee travels from Singapore on 17.12.2009 and arrives in Bangkok on the same day. Flies from Bangkok on 18.12.2009 and arrives in
-
I need some help in finding some documentation or getting some information on BDC processing. We have some consultants in France helping us with a project and the developer is using BDC code like FORM BDC_DYNPRO USING PROGRAM DYNPRO. CLEAR BDCDATA.