Why RandomAccessFile inserts space before each character while writing?
Ater running the following code, the file test.txt contain:
a b c d e f g h i j k l m n o p q r s t u v w x y z
Why writeChars() inserted a space before each charecter?
How to avoid this unwanted insertion?
try {
RandomAccessFile raf = new RandomAccessFile ("c:/test.txt", "rw");
raf.writeChars("abcdefghijklmnopqrstuvwxyz");
raf.close();
catch(Exception e) {
System.out.println(e.getMessage());
}
a char in java is a 16 bit datatype. (Allowing special chars like Norwegian ��� ���, German �� and many more from many languages). The ASCII system uses bytes for characters. (Allowing only 256 different chars). If you reed the file as byte you must write it as bytes as well. If you write the file as chars (16 bit cars) you must read the file as (16 bit) chars as well.
Similar Messages
-
Need to 5 spaces before each paragraph and 5 lines between paragraphs
Hello,
I need to write a program to insert 5 spaces (indent) before each 1st line of the paragraph and 5 spaces between each paragraph....I am new to java so I don't understand everything I write and I try and use what is out of the book...so far have done well until this assignment. My program below does create a new history.d2 file but it is blank....anyone have any input to offer or can you help me understand where I am going wrong in the program....thank you kindly.
I am playing with the program now just to see if I can find my error but of course don't fully understand the function of every line so having trouble finding my error.....at the end of my program is the file of what I am trying to edit into the new file history.d2.
import java.io.*; //import class we need in order to read from a file
import java.util.Scanner; //import class we need in order to read from a file
public class History //class History
public static Scanner inFile;
public static PrintWriter outFile;
public static void main(String[] args) //main method
throws IOException //a pre-defined Java exception - if file history.d1 not found, throws IOException error
String inputString;
// int index;
Scanner inFile= new Scanner(new FileReader("history.d1")); //it opens history.d1
PrintWriter outFile= new PrintWriter(new FileWriter("history.d2")); //instantiates an output file with the name "history.d2"
while (inFile.hasNextLine())
inputString=inFile.nextLine();
// index=inputString.indexOf(' ');
// while (index != -1)
if (inputString.length()!= 1)
outFile.println(" ");
else if (inputString.length() == 1)
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
outFile.close();
inFile.close();
history.d1 file:
The Abacus (which appeared in the sixteenth century) was the
first calculator. In the middle of the seventeenth century
Blaise Pascal, a French mathematician, built and sold gear-
driven mechanical machines which performed whole number
addition and subtraction. (Yes, the language Pascal is named
for him.)
Later in the seventeenth century a German mathematician
Gottfried Wilhelm von Leibniz built the first mechanical
device designed to do all four whole number operations:
addition, subtraction, multiplication and division. The
state of mechanical gears and levers at that time was such
that the Leibniz machine was not very reliable.
It wasn't until the nineteenth century that the next major
step was taken, this time by a British mathematician.
Charles Babbage designed what he called his analytical
engine. His design was too complex for him to build with the
technology of his day, so his design was never implemented.
His vision, however, included the important components of
today's computers. His design was the first to include a
memory so that intermediate values did not have to be re-
entered. His design also included the input of both numbers
and mechanical steps on a type of punched card developed in
the late eighteenth century by Joseph Jacquard to be used
with a mechanical loom.
Ada Agusta, Countess of Lovelace, was a most romantic figure
in the history of computing. Ada, the daughter of Lord Byron
(the English poet), was herself quite a mathematician. She
became interested in Babbage's work on the analytical engine
and extended his ideas (and corrected some of his errors).
Ada is credited with being the first programmer. The concept
of the loop--a series of instructions that repeat--is
attributed to her. Ada, the language used by the Department
of Defense, is named for her.
During the later part of the nineteenth century and the
beginning of the twentieth century advances were made
rapidly. William Seward Burroughs produced and sold a
mechanical adding machine (that worked!). Dr. Herman
Hollerith developed the first electro-mechanical tabulator
which used a punched card. Data was represented by holes
punched on the card in certain positions. Descendants of
this card are still in use today. Dr. Hollerith formed a
company that is known today as IBM.
In 1936 a theoretical development took place that had nothing
to do with hardware per se but profoundly influenced the
field of Computer Science. Alan M. Turing, another British
mathematician, invented an abstract mathematical model called
a Turing machine, laying the foundation for a major area of
computing theory.. The most prestigious award given in
Computer Science (equivalent to the Fielding Medal in
Mathematics or a Nobel Prize in other sciences) is the Turing
Award, named for Alan Turing. A current Broadway play deals
with his life. Analysis of the capabilities of Turing
machines is a part of the theoretical studies of all Computer
Science students.
By the outbreak of World War II, several computers were under
design and construction. The Harvard Mark I and the ENIAC
are two of the more famous machines of the era. John von
Neumann (an American mathematician this time) who had been a
consultant on the ENIAC project started work on another
machine known as EDVAC which was completed in 1950. In 1951
the first commercial computer, UNIVAC I, was delivered to the
Bureau of the Census.
Von Neumann is credited with the development of two very
important concepts. The first is that the instructions that
operate the machine should be stored in the machine along
with the data to be operated on. The second is that data
(and instructions) should be represented in the binary number
system rather than the decimal number system.
The general organization of a computer has remained constant
over the last 40 years. This organization or architecture is based
on the ideas of von Neumann and bears his name. The
essence of this architecture is sequentiality. That is,
instructions (a program) are stored in sequential memory
locations in binary form and are executed in sequence, one
after the other.Each paragraph is terminated in your text file by a newline character. So effectively what scanner.readLine() is doing is reading a paragraph of text.
1. Read paragraph into String (readLine())
2. Print or prefix 5 spaces to String.
3. Print 5x newline character
Mel -
BufferedReader Problem (inserting space after every character)
(This is a message I sent to an Aglet forum, however I thought maybe someone here could help me with the BufferedReader problem...with the spacing...read below)
-Blake
ok here's what I'm attempting to do.
I have a Master Aglet that creates a slave which is dispatched to a remote site. The Slave then opens a log file, reads it, and then is supposed to read the file line by line and send each line as a message back to the Master. As the master receives each line it appends the line to the window it created earlier.
I don't know what the problem is...it won't display the log file in the master window.
It does display each line on the console window.I added a println() function to make sure the String array was getting the information. There is a small problem with that as well because it inserts a space after EVERY character (BufferedReader problem??)...what is up with that? for example:
If the log file looked like: This is a log file entry.
the console looks like this when it is printed: T h i s i s a l o g f i l e e n t r y .
.... I had done something in a similiar program...and it worked just fine. here's some source code:
<b>Master:</b>
else if (msg.sameKind("Log")) {
try {
//println for testing purposes
System.out.println(msg.getArg());
appendMessage(" " + msg.getArg() + "test \n");
} catch (Exception e) {
System.out.println(e.toString());
<b>Slave: </b>
File log = new File("C:\\Aglets2.0.2\\public\\WINDOWSUPDATE.log");
FileReader fr = null;
try{
fr = new FileReader(log);
} catch (FileNotFoundException e) {
System.out.println(e);
BufferedReader br = new BufferedReader(fr);
//Get filename of log
try {
Message msg = new Message("FileName", log.getName());
mProxy.sendOnewayMessage(msg);
} catch (InvalidAgletException iae) {
System.out.println(iae.toString());
} catch (Exception e) {
System.out.println(e.toString());
//read each line of file and send back to Master as a message
try{
int i = 0;
while ((s = br.readLine()) != null) {
i++;
count = i;
for (int j = 0; j < count; j++)
System.out.println(s[j]);
//send message back to Master Aglet with log file information
try {
Message msg = new Message("Log", s[j]);
mProxy.sendMessage(msg);
} catch (InvalidAgletException iae) {
System.out.println(iae.toString());
} catch (Exception e) {
System.out.println(e.toString());
//close file reader
fr.close();
} catch (IOException e) {
System.out.println(e.toString());
}actually i did declare s, you just don't see it there because i only posted some of the code....
I fixed the "spacey" problem by using a FileInputStream instead of a bufferedreader....
like this (i'll post the whole code here:
public class Slave extends BlindAglet {
AgletProxy mProxy = null;
boolean back = false;
char[] c = new char[1000];
BufferedReader br = null;
int count;
// Do some tasks when the aglet is created
public void onCreation(Object init) {
// Must make a note of the master here
mProxy = (AgletProxy)init;
// Add our own listener and adapter
addMobilityListener(
new MobilityAdapter() {
// Using this as a safety check in case we get caught in a loop in the same host
public void onArrival(MobilityEvent event) {
try {
mProxy.sendMessage(new Message("NewSlaveProxy", getAgletContext().getAgletProxy(getAgletID())));
} catch (InvalidAgletException iae) {
System.out.println(iae);
} catch (NotHandledException ex) {
System.out.println(ex);
} catch (MessageException ex) {
System.out.println(ex);
//Are we back to origin?
if(back) {
back = false;
try{
FileWriter fw = new FileWriter("test.txt");
for (int i = 0; i < count; i += 2){
fw.write(c);
fw.close();
} catch (IOException e) {
System.out.println(e);
dispose();
dispose();
); /* End of Adapter */
public void run() {
// Are we at home base?
if (atHome()) {
try {
dispatch(new URL("atp://darklord:4434"));
} catch (Exception e) {
System.out.println(e.toString());
try{
File log = new File("C:\\Aglets2.0.2\\public\\WINDOWSUPDATE.log");
FileInputStream f0 = new FileInputStream(log);
//Get filename of log
try {
System.out.println(log.getName());
Message msg = new Message("FileName", log.getName());
mProxy.sendOnewayMessage(msg);
} catch (InvalidAgletException iae) {
System.out.println(iae.toString());
} catch (Exception e) {
System.out.println(e.toString());
//read each line of file and send back to Master as a message
try{
int size = f0.available();
int i = 0;
for (i = 0; i < size; i++) {
c[i] = (char) f0.read();
//send message back to Master Aglet with log file information
try {
Message msg = new Message("Log", c[i]);
mProxy.sendOnewayMessage(msg);
} catch (InvalidAgletException iae) {
System.out.println(iae.toString());
} catch (Exception e) {
System.out.println(e.toString());
count = i;
} catch (IOException e) {
System.out.println(e.toString());
} catch (FileNotFoundException e) {
System.out.println(e);
back = true;
returnHome();
* Returns true if the current host is our origin
public boolean atHome() {
if (getAgletInfo().getOrigin().equals(getAgletContext().getHostingURL().toString()))
return true;
else
return false;
* Allows a slave to contact it's master and ask for a retraction.
public void returnHome() {
try {
Message msg = new Message("RetractMe");
msg.setArg("url", getAgletContext().getHostingURL());
msg.setArg("id", getAgletID());
mProxy.sendOnewayMessage(msg);
} catch (InvalidAgletException iae) {
System.out.println(iae.toString());
} catch (Exception e) {
System.out.println(e.toString());
* Return a reference to our Master's proxy
public AgletProxy getMasterProxy() {
return mProxy;
} /* End of Class -
Insert space before the capital letter in a word
Hi,
I have a column with list of names like
reports
admissionPage
topHighCost
requestedReports
Like this there will be many rows. I want to add space before the capital letter.
This is a rdl query. Is it is possible to do in SSRS? Or we should do in Tsql? Please help me in this issue.
Thanks in advance..
BALUSUSRIHARSHAIts going to be pretty complicated, in my opinion, to do this in SSRS.
For t-sql, I developed a function for you.
CREATE FUNCTION fn_text_with_space(@STRING VARCHAR(MAX))
RETURNS
VARCHAR(MAX)
AS
BEGIN
DECLARE @NEWSTRING VARCHAR(MAX) = '';
declare @count int = 1;
WHILE @COUNT <= LEN(@STRING)
BEGIN
IF SUBSTRING(@STRING, @COUNT, 1) COLLATE Latin1_general_CS_AS = UPPER(SUBSTRING(@STRING, @COUNT, 1)) COLLATE Latin1_general_CS_AS
BEGIN
SET @NEWSTRING = @NEWSTRING + ' ' + SUBSTRING(@STRING, @COUNT, 1);
END
ELSE
BEGIN
SET @NEWSTRING = @NEWSTRING + SUBSTRING(@STRING, @COUNT, 1);
END
SET @COUNT = @COUNT + 1;
END
RETURN @NEWSTRING;
END -
It happens randomly. The spaces between each letter are huge. It happens on websites that you print and also in your email (webmail).
Lets say you printing an email, then it will print and all the characters are jumbled up, then when you click reply on the same email and press print, then it print fine. It just the first time I have seen this and only since we updated to Firefox 7.
Thank you'''bold text'''(1) Firefox's built-in post-crash page has not been a real HTML page for a long time (for example, from the time of Firefox 22, see: [https://support.mozilla.org/en-US/questions/968212 Want to save LOTS of versions of "Restore Session.xht" from the "oops ..." page for later use]). If you had this working differently with Firefox 25, that might have been created by an extension.
You can check to see whether extensions are disabled or need an update on the Add-ons page. Either:
* Ctrl+Shift+a
* orange Firefox button (or Tools menu) > Add-ons
In the left column, click Extensions. The disabled extensions cluster toward the bottom of the list. To poll for updates, use the "gear" button above the list and choose Check for Updates.
If you used the Reset feature (or Firefox automatically did a reset due to some problem during upgrading), you will need to reinstall missing extensions. The reset feature creates a folder on the desktop named Old Firefox Data. Do you have that folder? There may be data you can recover from it.
(2) There are many ways for history to get cleared, both internal to Firefox and external. Could you double-check your Privacy settings?
orange Firefox button (or Tools menu) > Options > Privacy
* The "Firefox will" drop-down says Remember History: Firefox shouldn't be clearing history, but an add-on or external software could do it
* The "Firefox will" drop-down says Use custom settings for history: inspect the "Clear history when Firefox closes" setting to make Firefox isn't set to clear history. Also check your add-ons and consider external software.
Firefox normally accumulates months of history. However, some of Firefox's database sizes are based on disk space available. If your hard drive is very full, Firefox might reduce the amount of history stored. -
How do I insert a space between each letter? i.e. ABC becomes A B C
I have a long strand of characters that I would like to insert spaces between and doing it manually is not practical. Can anyone suggest a shortcut or a way to save me a day of sitting and hitting right arrow space bar??
I need to turn everything into a graph where each Letter, Number and Character is in its own column.
In this context, set up Tabulators where each and every one is defined as centered. This way, the variable set widths of the sorts (letters, glyphs) will align vertically.
Note that if you are working with Apple Advanced Typography or Microsoft OpenType font files, your font file may have a special subset of monospaced figure (number) sorts termed Tabular.
The monospaced figure (number) sorts may either stand on the baseline to align with UPPER CASE or have strokes ascending above and descending below the baseline to align with lower case.
Your font file may also have other special subsets of figure (number) sorts that are proportionately spaced. You should play with these subsets to see which figures will work well for you.
In typography (as in photography and lithography) what looks right is rights. Intelligent fonts for composition and intelligent profiles for separation are there to help you with the visuals.
/hh -
why does a text banner pop up while in a text converstaion? only the sound alerted before iOS 6.
but that only started with iOS 6. prior, the text tone would sound when you were in a different conversation. I like the banner but it's annoying when I'm already in the text screen.... understand the question?
-
Has to type each character twice while supplying command in Open VISA test panel
has a set of commands to work witha system connected to the MS windows PC. when I trype the commands in Hyperterminal (with/without ) they are yielding the expected results.
in LabVIEW, to get the expected results I MUST has to type 'each character' in the command Twice(except blank space) in the Open VISA test panel (viWrite/viRead). If I give the command is given the usual way(with each character typed only once), the result always is 'illegal command'.....the same works fine in the Hyperterminal.What confused Ashwin is that you said "In LabVIEW". OK, so you're using the MAX test panel. There's one thing that's not clear. You said "when I trype the commands in Hyperterminal (with/without )". With/without what? How is your Hyperterminal session configured? Have you tried something like PortMon to see what's actually being sent from the serial port driver?
-
After downloading almost all of it, I get an error that there is no enough space. Why doesn't the store check to see if I have enough free space before proceeeding with the order?
How do I get a refund?Well, with apps genneraly you do get told ahead of time. I'm not sure of the current algorithm with movies though.
Why not just clear up some space? You can check your usage in your settings btw. -
How to increase space before a Heading
Hi, Three things are really getting to me in Pages 9.
1. Can I a dotted line in the TOC for each line item. e.g.
Heading 1.................2
Heading 2..............3
Heading 2..............4
2. How do I add space before the style at the top of the page. eg.
--- top of page ----
[space
of
lets
say 5 cm]
Heading 1
I can add the space IF I add an empty paragraph as the first line and add a value to "before paragraph' text inspector.
3. Can I create a TOC which will display the headings I have in the floating text boxes?
thanks in advanceHi stnsw,
Welcome to Apple discussions and the Pages '09 forum.
singletracknsw wrote:
Hi, Three things are really getting to me in Pages '09.
1. Can I a dotted line in the TOC for each line item.
The dotted line running from the text to the next tab stop is called a 'leader.'
A look at the article_Setting Tab Stops to Align Text_ in Chapter 5, Working with Text in the Pages '09 User Guide will explain how to set leaders to tab stops. The article starts on p. 91
Short answer: use the Tab section of the Text Inspector.
2. How do I add space before the style at the top of the page. eg.
Several ways.
• An inserted shape, either floating and set to cause wrap using the button that prevents text to the right and left of the object, or inline, and set in a paragraph of its own above the first 'real' text on the page. The object may be white, transparent, or set to any colour with opacity set to zero.
• Type a return character before the first text on the page. Select the return and set the font size to 144 points (two inches) Adjust the size to taste using command-+ (larger) and command- - (smaller).
• Use the Inspector to set the space before the first paragraph, as you described.
I can add the space IF I add an empty paragraph as the first line and add a value to "before paragraph' text inspector.
3. Can I create a TOC which will display the headings I have in the floating text boxes?
Not using the TOC tools in Pages.
You'll find the Pages '09 User Guide a valuable (and mostly easy to read) resource. It can be downloaded through the Help menu in Pages.
Regards,
Barry
Regards,
Barry -
Hi, I've got this dumb thing where the text I imported from Word has an extra space after/before each paragraph that I don't want. I tried both find/replacing ^p^p with ^p in the text section, and find/replacing ~b~b+ with \r in the GREP section, and neither worked. As you can see in this screenshot, with hidden characters shown, it LOOKS like there's only one paragraph symbol between each, as opposed to two. What the heck is going on here? Why can't I get rid of it? CS3! Mac!
As MW design wrote it is the paragraph property.
BTW it is important never to work with 2 return to get space between paragraphs. Defining different paragraph styles with proper spaces is the correct way to work in InDesign (but also in Word or Quark or …) -
Layout Break Space Before Paragraph
I am using a layout break in pages. I have a heading style with a background fill on my paragraph. I have a before paragraph space of 14. If I place the heading style right after a layout break (at the top of the new layout section) it eats my before paragraph space. Seems like a bug but I thought I would ask if anyone has a solution or workaround.
Thanks
ChrisIt may not be completely intuitive, but that is how it is supposed to work. Space before and space after apply between paragraphs in a layout section but not at the beginning or end of a layout section or at the beginning or end of a page. It is sort of like the way the last character in a word can be right against the margin and yet the next line does not have to start with a space; the area outside the margins can "count" for this kind of white space. A layout break works like a margin here, even if it is in the middle of a page (and not necessarily preceded by white space).
If you are producing a multipage document, you normally want the tops of the text blocks of each page to line up at the margin, not jump up and down if one page happens to start with a new paragraph that has a space before set.
To deal with your situation with needing the white space at the beginning of a new layout section, with the cursor in that section, use the Layout pane of the Inspector to set the "Before" margin of that section to, for example, 14 pts. -
How can I control the space before and after text in a table
Hello
I have a series of icons with descriptions, these are lined up with icons on the top row and description text in the bottom row. Each icon and description is divided by a stapled line.
The text is of varying width, therefore the column width must also wary. However I would like to make the space before and after the text equal in all instances (See image).
If there is anyone that can tell me how to do this with tables or any other tools I would be very thankful.The only way I can think of to maintain equla spacing between the text ov vartying lengths and the vertical lines is to put each icon/text pair in it's own frame fitted to content, make each vertical line a separate object, then select them all and distribute the spacing.
-
Space Before Text in Word Document
Having generated a word document I noticed that thre was
space before all my paragraphs. Simple to fix, or so I thought.
When I checked the paragraph setting s in word there was no space
before the paragraph. Checked the paragraph above, and that did not
have space after set.If the extra spacing is not in your Word output files, then
it must be in your RH source files.
There's either something at each of the paragraphs, or in the
HEAD section of the topic, or in your CSS style sheet assigned to
the topic. The proximity of styling info to its content is what
determines its effect.
Good luck,
Leon -
How to insert new line char while writing bytes into file
Hello Sir,
Is it possible to insert the new line character in set of String variables and stored them into bytearray ,then finally write into File?
This is the sample code which i tried:
File f = new File(messagesDir,"msg" + msgnum + ".txt");
FileOutputStream fout = new FileOutputStream(f);
String fromString = "From: "+msg.getFrom()+"\n";
String toString = "To: "+msg.getTo()+"\n";
String dateString = "Sent: "+msg.getDate()+"\n";
String msgString =msg.getBody()+"\n";
String finalString=fromString+toString+dateString+msgString;
byte[] msgBytes = finalString.getBytes();
fout.write(msgBytes);
fout.close();in the above code , i tried to add the new line as "\n" in end of each string. but when i look into the generated files msg1.txt , it contains some junk char [] .
please provide me the help
regards
venkibut it has still shown the the junk char, its not able
to create the new line in the created file i am afraid
how am i going to get the solution?:(Do not be afraid dear sir. You are obviously using a windows operating system or a mac operating system. On windows a newline is "\r\n" not '\n', and on a mac a newline is '\r', not '\n'. If you make that correction, dear sir, your program will work.
However, there is a better way. First, you probably want to buffer your output if you are going to write more than one time to the file, which will make writing to the file more efficient. In addition, when you buffer your output, you can use the newLine() method of the BufferedWriter object to insert a newline. The newline will be appropriate for the operating system that the program is running on. Here is an example:
File f = new File("C:/TestData/atest.txt");
BufferedWriter out = new BufferedWriter(new FileWriter(f) );
String fromString = "From: Jane";
out.write(fromString);
//Not written to the file until enough data accumulates.
//The data is stored in a buffer until then.
out.newLine();
String toString = "To: Dick";
out.write(toString);
out.newLine();
String dateString = "Sent: October 27, 2006";
out.write(dateString);
out.newLine();
out.close();
//Causes any unwritten data to be flushed from
//the buffer and written to the file.
Maybe you are looking for
-
Hi Gurus We are designing process chain for our BW solution. We have identified the dependancies of various loads which includes flat file loads and loads from R/3. Now we would like to control ERP and BW jobs by Control M . I have the following ques
-
Dates in calendar now not BOLD in calendar view
Environment: W2K3 server; BPS software; 6 users; all BB8830 curves; all WinXPP w/ Ofc2003 I'm confused. I have one of my user's handhelds. A new appointment was made in Outlook for a week from May 5 - May 12. The appt showed up correctly in the hh. T
-
Hi experts! I develop smart synchronization application (2-way). After synchronizing I can see on MI client all data, than I change it and with next synchronization I tried to send it to midleware. Here is a problem,data doesn't appear after synchron
-
ADF Faces - how do stop table navigation?
im have <af:table with rangeChangeListener="#{ResPage.RangeChL}" on JSF page in RangeChL im check on last rows in ResultSet: if(sr.rs.isLast()) System.out.println("%%%%%%%%AbortProcessingException"); // throw new AbortProcessingException("EEEENNNNDDD
-
Hi I am currently a windows user, but I want to take the big step to MAC, I work mostly with Microsoft office, and a very few Adobe products (use Illustrator 1 hour per day), and I take my notebook every day from my office to my house, but I cant dec