Is there a way how i can display the contents of a binary file in a textArea?
14 1507
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?
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.
.. 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 ..
? ?
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.
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.
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!
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.
You are still leaving us guessing. Are you trying to write a hex editor?
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.
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.
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. - import java.awt.BorderLayout;
-
import java.io.DataInputStream;
-
import java.io.File;
-
import java.io.FileInputStream;
-
-
import javax.swing.JDialog;
-
import javax.swing.JTextArea;
-
import java.awt.*;
-
import javax.swing.*;
-
-
public class Scores {
-
-
private JTextArea textArea;
-
String[] scores = null;
-
static final String dataFile1 = "players.dat";
-
public Scores() {
-
super();
-
-
try{
-
JDialog dialog = new JDialog();
-
dialog.getContentPane().setLayout(new BorderLayout(10, 10));
-
Test4Rx imagePanel = new Test4Rx("scores.gif");
-
dialog.add(imagePanel, "North");
-
dialog.add(new Test4Rx("scores.gif"));
-
-
File aFile = new File( "players.dat" );
-
// create an output stream to the file
-
FileInputStream aFileInStream = new FileInputStream ( aFile );
-
// create a data output stream to the file output stream
-
DataInputStream aDataInStream = new DataInputStream ( aFileInStream );
-
-
-
textArea = new JTextArea();
-
String string = dataFile1;
-
textArea.append(string + "\n");
-
textArea.setBackground(Color.orange);
-
textArea.setFont(new Font("Times New Roman", Font.BOLD, 14));
-
textArea.setEditable(false);
-
textArea.setForeground(Color.red);
-
-
dialog.getContentPane().add(BorderLayout.CENTER, textArea);
-
dialog.setTitle("Scores");
-
dialog.setSize(350, 350);
-
-
dialog.setVisible(true);
-
-
}catch (java.io.FileNotFoundException f) {
-
JOptionPane.showMessageDialog(null, "File not found.");
-
-
}catch (Exception e){
-
e.printStackTrace();
-
}
-
-
}
-
-
public static void main(String[] args){
-
new Scores();
-
}
-
-
}
but instead of displaying the contents of the binary file (i.e the scores) it just displays "players.dat". -
dataFile1 = "players.dat";
-
...
-
String string = dataFile1;
-
textArea.append(string + "\n");
-
I've edited out irrelevant lines. Why the text area displays "players.dat" should be clear now.
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.
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. Sign in to post your reply or Sign up for a free account.
Similar topics
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,...
|
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
|
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...
|
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 ?
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |