• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

output a literal '?'

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jake mullet
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1012
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1012
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1012
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh yea, if you need lower case z and x, their ascii numbers are:
z = 122
x = 120
 
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
jake mullet
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1012
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Attractive, successful people love this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic