This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes output a literal   '?' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "output a literal   Watch "output a literal   New topic
Author

output a literal '?'

jake mullet
Greenhorn

Joined: May 09, 2001
Posts: 15
why when i am trying to print the character at a particular place in the file it gives me a '?' instead of the 'Z' i'm looking for. there are no ?'s in the entire file so I dont know what the deal is is it a typecast error??? thanks
i must be a lepar or something, either that or my questions are too difficult for this board cause no one seems to answer my questions.... please someone ...anyone..
heres the code so far
import java.io.*;
import java.util.*;

public class injRecFix{
static PrintWriter prntWrter;

public static void main(String[] args){
char[] chBuffer =null;
boolean bReadFile = false;
String sINFileName = null;
String sOUTFileName = null;
int i;
int iSize = 0;
char chIsIt = 0;
InputStream fin;
File outputFile = new File("newPunchFile.txt");

if(sINFileName == null)
sINFileName = "Punch.001";

try {
fin = new FileInputStream(sINFileName);
prntWrter = new PrintWriter(new FileWriter(outputFile));
} catch (IOException except) {
sINFileName = "Punch.001";
try {
fin = new FileInputStream(sINFileName);
} catch (IOException eIO) {
fin = null;
}
}
if(fin != null) { // dumping PunchFile into chBuffer
try {
chBuffer = new char[fin.available()];
int iC = 0;
while(iC < chBuffer.length) {
i = fin.read();
chBuffer[iC] = (char)i;
iC++;
}
fin.close();
bReadFile = true;
} catch (IOException except) {
bReadFile = false;
}
}
if (bReadFile) {
// Convert buffer into a string.
String sBuffer = new String(chBuffer, 0, chBuffer.length);
iSize = sBuffer.length();
System.out.println("the length of the file is: " + iSize);
System.out.println("the length of the Z is: " + (iSize - 10) );
chIsIt = ((char)(iSize - 10));
System.out.println("a " + chIsIt + " is at that space");
// sBuffer.charAt(812)
//System.out.println(sBuffer.length());
}
}//end main()
}//end class injRecFix
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
No we really love you, it's just that you are so much ahead of us .
Acutally, I have a REAL job and try to squeeze this in in 5 minute chunks. Your code required actually spending some TIME thinking about it, and I just didn't have the time today. Sorry.
The JVM prints out a ? if you do not have the proper font to work with the actual symbol that it is supposed to be. I would guess that if you look at the file in hex, you will find that it is not truely a Z, it is something else that your PC is translating to a Z.
Sorry - got to go. Good Luck.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
i compiled your code and created my own "Punch.001" file to see what happens... it would help if i knew what was supposed to be passed in.
anyway, here is the output i got:
the length of the file is: 50
the length of the Z is: 40
a ( is at that space

the problem is that i do not have any "(" in my file... i haven't studied your code yet, but i will see if i can give it a look tonight when i get home.


what?
jake mullet
Greenhorn

Joined: May 09, 2001
Posts: 15
Thank you so much for your help and replies. I am trying to learn and this site seems like the best place.
Greg:
I have a file that is downloaded from a server each day with records on each line. the file is called PUNCH.001. each file contains an X on the 6th element of the first line of the daily PUNCHfile and a Z on the 10th element of the last line of the file. Problem is, sometimes the process fails and the file gets cut off in the middle and then starts a new PUNCH.002--so..the first file is missing the "Z" line and the second is missing the "X" line. I have to check this file everyday, and if this wierd cutoff thing happens I have to manually cut and paste the two files together, arghh- so essentially I want to write a the program to check the PUNCH.001 file to see if there is the 'X' and 'Z' line and if it is missing the 'Z' line, go grab the punch.002 file, check if it has the 'X' in the line 1(which it shouldn't) and lastly put the two files together where they were split. anyhelp whatsovever is awesome. Thanks again
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
well, i am pretty new at this too. i am comming from a c++ background and trying to learn java style. i am going to look at your code tonight because i think it will help me as well.
so far, i think you might want to use

more to come... if anyone thinks i am off track here, please let me know!
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
okay, jake... this is a mess, but i think it does what you want it to. i didn't look too hard at your code because i am more comfortable with vectors. i know they are bad programming style for java, but i got used to them in c++. anyway, you should be able to modify this to work with your program.
this code might not copy to your text editor neatly, so i put it on my website: Click for file

basically, it reads in the first file to a vector and then checks the 10th character from the end of the line. if it is a capital "Z", then it sends the vector to the new .txt file.
otherwise, it reads the 2nd file into another vector and checks the 6th character in the first line. if it is NOT a capital "X" then it prints both vectors to the new .txt file.
i see that you are using (char)int, but i cannot figure out what it is doing wrong. let me know if you need me to explain my mess further... and if this works.

[This message has been edited by Greg Harris (edited May 09, 2001).]
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
oh yea, if you need lower case z and x, their ascii numbers are:
z = 122
x = 120
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
The reason your code is printing "random" characters is that you are casting the position in the file to a char, rather than getting the actual character at that point.
Consider replacing the line
chIsIt = ((char)iSize - 10));
with
chIsIt = sBuffer.charAt(iSize - 10);
Does this help?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
jake mullet
Greenhorn

Joined: May 09, 2001
Posts: 15
You guys are awesome. Frank, yours works too. and Greg, can't thanks you enough. I can't wait to get good at this stuff and then I can help people out too. I'm still working with it, I'll keep you guys posted.
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
no problem... but i am not that good yet. if i were, i would have seen what frank did. i do not mind at all because this is the way i learn.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: output a literal '?'
 
Similar Threads
FileInputStream Initialization...
problem, please help
tokenizer
using .length()
trouble with a file