473,396 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

TextArea

35
Is there a way how i can display the contents of a binary file in a textArea?
Feb 15 '08 #1
14 1507
r035198x
13,262 8TB
Is there a way how i can display the contents of a binary file in a textArea?
A Texarea displays text. Do you want to display the binary representation(ones and zeros) of the file?
Feb 15 '08 #2
saytri
35
No, i want to display the data not the one's and zero. Thats why i am having problems. Because since binary files are not in a human readable mode, i want that when they are displayed on the textArea they are human readable (not with the zeros). Is there a way how i could display them in this way?
Thanks.
Feb 15 '08 #3
r035198x
13,262 8TB
.. Because since binary files are not in a human readable mode, i want that when they are displayed on the textArea they are human readable ..
? ?
Feb 15 '08 #4
saytri
35
When you open a binary file like in a text editor, you can't read data, because its not readable. It contains jumbled up text and characters. Its not like a textfile where you can edit or read the data contained.
Feb 15 '08 #5
r035198x
13,262 8TB
When you open a binary file like in a text editor, you can't read data, because its not readable. It contains jumbled up text and characters. Its not like a textfile where you can edit or read the data contained.
I know. So what do you want to do since you you know this as well.
Feb 15 '08 #6
BigDaddyLH
1,216 Expert 1GB
You question is the equivalent of asking "how long is a piece of string"? Only you know the format of the file. Unless you don't, either!
Feb 15 '08 #7
saytri
35
The problem is that i don't know how to call a binary file, to be displayed in a textArea. I know how to display a textfile in a textArea, but since binary files contain unreadable data, i can't display the contents of a binary file like i display a textfile. When i tried to display the contents of the binary file like i display them when they are stored in a textfile, it displays jumbled up characters (the way binary file stores them). I want to display the contents in a textfile in a readable mode.
Sorry guys if i'm not making myself clear. Hope that this would make it clearer. Thanks a lot.
Feb 15 '08 #8
BigDaddyLH
1,216 Expert 1GB
You are still leaving us guessing. Are you trying to write a hex editor?
Feb 15 '08 #9
saytri
35
No, its just i am doing like a quiz. And my tutor told me that instead of saving the scores in a textfile i should store them in a binary file since binary files are more secure. And i want to display these scores into a JTextArea. I'm still a beginner and so i'm not just of an expert in java. Hope that this would give a more clearer idea of what i'm doing. Thanks a lot, and sorry for the trouble.
Feb 15 '08 #10
BigDaddyLH
1,216 Expert 1GB
No, its just i am doing like a quiz. And my tutor told me that instead of saving the scores in a textfile i should store them in a binary file since binary files are more secure. And i want to display these scores into a JTextArea. I'm still a beginner and so i'm not just of an expert in java. Hope that this would give a more clearer idea of what i'm doing. Thanks a lot, and sorry for the trouble.
Take the code you used to write data to a file and reverse it. Now you've recovered the data structure and you can display it as you like.
Feb 15 '08 #11
saytri
35
Ok thanks a lot. I tried doing this, but instead of displaying the contents of the binary file (i.e the scores) it just displays "players.dat". What am i doing wrong? Thanks a lot. I really appreciate all your help.

Expand|Select|Wrap|Line Numbers
  1. import java.awt.BorderLayout;
  2. import java.io.DataInputStream;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5.  
  6. import javax.swing.JDialog;
  7. import javax.swing.JTextArea;
  8. import java.awt.*;
  9. import javax.swing.*;
  10.  
  11. public class Scores {
  12.  
  13. private JTextArea textArea;
  14.  String[] scores = null;
  15.  static final String dataFile1 = "players.dat";
  16. public Scores() {
  17. super();
  18.  
  19. try{
  20. JDialog dialog = new JDialog();
  21. dialog.getContentPane().setLayout(new BorderLayout(10, 10));
  22. Test4Rx imagePanel = new Test4Rx("scores.gif");
  23. dialog.add(imagePanel, "North");
  24. dialog.add(new Test4Rx("scores.gif"));
  25.  
  26. File aFile  = new File( "players.dat" );
  27.       // create an output stream to the file
  28. FileInputStream aFileInStream = new FileInputStream ( aFile );
  29.       // create a data output stream to the file output stream
  30. DataInputStream aDataInStream = new DataInputStream ( aFileInStream );
  31.  
  32.  
  33. textArea = new JTextArea();
  34. String string = dataFile1;
  35. textArea.append(string + "\n");
  36. textArea.setBackground(Color.orange);
  37. textArea.setFont(new Font("Times New Roman", Font.BOLD, 14));
  38. textArea.setEditable(false);
  39. textArea.setForeground(Color.red);
  40.  
  41. dialog.getContentPane().add(BorderLayout.CENTER, textArea);
  42. dialog.setTitle("Scores");
  43. dialog.setSize(350, 350);
  44.  
  45. dialog.setVisible(true);
  46.  
  47.           }catch (java.io.FileNotFoundException f) {
  48.              JOptionPane.showMessageDialog(null, "File not found.");
  49.  
  50. }catch (Exception e){
  51. e.printStackTrace();
  52. }
  53.  
  54. }
  55.  
  56. public static void main(String[] args){
  57. new Scores();
  58. }
  59.  
  60. }
Feb 15 '08 #12
BigDaddyLH
1,216 Expert 1GB
but instead of displaying the contents of the binary file (i.e the scores) it just displays "players.dat".

Expand|Select|Wrap|Line Numbers
  1. dataFile1 = "players.dat";
  2. ...
  3. String string = dataFile1;
  4. textArea.append(string + "\n");
  5.  
I've edited out irrelevant lines. Why the text area displays "players.dat" should be clear now.
Feb 15 '08 #13
saytri
35
Ok i understood that(why its displaying players.dat. But how can i append the file, so it would display its contents. Because i can't figure out how to call the file to be displayed in the textArea. Thanks a lot for your help.
Feb 15 '08 #14
BigDaddyLH
1,216 Expert 1GB
Ok i understood that(why its displaying players.dat. But how can i append the file, so it would display its contents. Because i can't figure out how to call the file to be displayed in the textArea. Thanks a lot for your help.
Did you understand my advice in reply #11:
Take the code you used to write data to a file and reverse it. Now you've recovered the data structure and you can display it as you like.
Feb 15 '08 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Csaba Gabor | last post by:
What I'd like to do is to be able to set the font of a textarea element to the same font that another element is using (say, for example, an <INPUT type=text ...> element, but if that's a no go,...
1
by: Volt | last post by:
is there any way to select and mark part of text in textarea by regular expression? i need to select the first string in textarea whitch is like xxxxx,xxx where x is any character
5
by: Jesper Rønn-Jensen | last post by:
I have a textarea that must be limited to 70 characters. No big deal -- at least so I thought. * Textarea must not exceed 70 characters * Exceeding content must be cut off * Must work on input by...
4
by: TJS | last post by:
can the rows and columns of a textarea element with an id be changed on the fly ? if so is there an example ?
6
by: wperry1 | last post by:
I am writing a small database utility to catalog all of my favorite ASM/JS/VBS... functions and scripts on an asp page. Everything is going smoothly except for one thing that I can't quite seem to...
6
by: Tony | last post by:
The w3schools HTML tag reference for <textarea> http://www.w3schools.com/tags/tag_textarea.asp says that the attributes 'cols' and 'rows' are REQUIRED attributes for the textarea tag. Looking at...
4
by: Keith Bentrup | last post by:
Hi all, I wrote a simple search function to find text in a textarea where not all the text is visible (ie. the text box displays 10 lines but there may be more than 1000 lines to search). I can...
3
by: MikeK | last post by:
Ok, I've been noodling with this for several days now and I'm starting to go crazy. Does Apple's Safari browser support drag events on Textarea elements? The few specs and docs I've found seem to...
3
by: FunkHouse9 | last post by:
I'm working on a form to collect data in a textarea which and am trying to keep returns and spaces. I have a couple of functions that I Frankensteined together to replace returns with <br> and to...
5
by: a113n | last post by:
I have the following XSL code to handle textareas: <!-- Match TEXTAREA --> <xsl:template name="TEXTAREA" match="TEXTAREA"> <TEXTAREA ROWS="{@ROWS}" COLS="{@COLS}" NAME="{@NAME}"> <xsl:if...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.