Win a copy of Functional Design and Architecture this week in the Functional programming forum!

jake mullet

Greenhorn
+ Follow
since May 09, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by jake mullet

okay fellas, i have come a long way on my journey. ive been trying to write a class which contains a method searchFile(). all i want that method to do is: any text file that gets passed to my search method, read it in and check to see if it contains the two strings in it at all. I am close but I am missing something, any help is greatly appreciated thanks.
import java.io.*;
import java.util.*;
public class PunchFile{
private String xString = new String("00001X000001X057000000000CO083100");
private String zString = new String("07573Z07573");
static File fPun = new File("C:\\workfiles\\datafile.001");
public static void main(String args[]){
PunchFile pf = new PunchFile();
pf.searchFile(fPun);
int searchFile(file fFile){
fFile = fPun;
Vector vFile = new Vector();
BufferedReader brSearch;
String sOneLine;
brSearch = new BufferedReader(new FileReader(fPun));
sOneLine = brSearch.readLine();
while (sOneLine != null) {
vFile.add(sOneLineline);
sOneLineline = brSearch.readLine();

while(sOneLine != null){
if (!vFile.contains(xString)) {
System.out.println("no x line");
}
else if (!vFile.contains(zString)) {
System.out.println("no z line");
}
else {
System.out.println("this file has both lines");
}
}//end while2
line = br.readLine();
}//end while1
}//end method
}//end main
}//end class
20 years ago
Im using a WindowsNT system and I want my java program to to go into a diretory where three files exist. File1.txt, File2.txt, and Newbie.txt. I want to issue an command that deleted File1 and File2 and then renames Newbie.txt to File1.txt. Is this possible? I was looking up Runtime but its a little confusing
public Process exec(String del File1.txt);
public Process exec(String del File2.txt);
public Process exec(String ren Newbie.txt File1.txt);
Kinda confused. any help would be great. Thanks JM
20 years ago
Im sorry Im not experienced enough to understand, but I've never used RandomaccessFile. Do you know where there are any examples for what I need it for? thanks
20 years ago
Ok fellas, come a long way and i have learned a ton. The two files that I am putting together one after another in the new file is working but...the second file contains several lines at the begining that are contained at the end of the first file so i have duplicate records in the middle of the new file!! Im thinking of using the RandomAccesFile() but how would I implement this with the code I have already written, must it only deal with DataOutputStreams? I will try to visually show you what the two files look like before the program is run on them below then my code.

thanks for you guys help JM
(edited by Cindy to format code)

[This message has been edited by Cindy Glass (edited June 07, 2001).]
20 years ago
Thanks scott, you were exactly right and i appreciate your help, it does write the first file out now and then append the second to it!!! Wonderful, I only have one more issue to resolve and I will tryi to work it out myself, but if i get stumped ...ill be back
20 years ago
Thanks for the response scott, but I tried exactly what you said but the second file overwrites the first not appends to the end. any thoughts. Im sstill trying stuff in the meantime JM
20 years ago
Thanks alot for your response but I am confused as to how to use the same BufferedWriting, i dont use an append method? So i should go :
bufOutput = null;
FileReader inFlRd2 = new FileReader(f2);
BufferedReader bufInput2 = new BufferedReader(inFlRd2);
FileWriter outFlWr2 = new FileWriter(line);
thanks JM
20 years ago
first of thanks to people who help you guys make this stuff so much funner and easier to understand, now here is what i have come up with so far. I am trying to read these two files and then put them together and call them builtfile.txt right now it writes the first file fine, but instead of appending file2 to the end of the new file it overwrites it, how can i make this into a String buffer instead so I can use the appends() thanks again JM
import java.io.*;
import java.util.*;
public class testFile {
public static void main(String[] args){
File f1 = new File("C:\\file1.txt");
File f2 = new File(C:\\file2.txt");
File outFile = new File("C:\\builtfile.txt");

if(f1.exists() && f2.exists()) {
System.out.println("yes there are two files");
try {
FileReader inFlRd = new FileReader(f1);
BufferedReader bufInput = new BufferedReader(inFlRd);
FileWriter outFlWr= new FileWriter(outFile);
BufferedWriter bufOutput = new BufferedWriter(outFlWr);
String line;

line = bufInput.readLine();

while (line != null) {
bufOutput.write(line, 0, line.length());
bufOutput.newLine();
line = bufInput.readLine();

}//end while

bufInput.close();
bufOutput.close();
}//end try
catch (IOException e) {
e.printStackTrace();
}
try {
FileReader inFlRd2 = new FileReader(f2);
BufferedReader bufInput = new BufferedReader(inFlRd2);
FileWriter outFlWr= new FileWriter(outFile);
BufferedWriter bufOutput = new BufferedWriter(outFlWr);
String line;

line = bufInput.readLine();

while (line != null) {
bufOutput.write(line, 0, line.length());<----this overwrites!
bufOutput.newLine();
line = bufInput.readLine();

}//end while

bufInput.close();
bufOutput.close();
}//end try
catch (IOException e) {
e.printStackTrace();
}






}//end if
else {
System.out.println("Process ran ran normal, only one File exists");
}
}//end main
}//end class
[This message has been edited by jake mullet (edited June 06, 2001).]
[This message has been edited by jake mullet (edited June 06, 2001).]
20 years ago
hi friends, if i wanted to check if to see if a file exists in certain directory do i just use the .exists()? for example on a good day there should be only one file in C:\stuff\ called download1.txt, on bad days there are 2 files a download1.txt and download2.txt , so i guess i should just check initially are there 2 files? no then go the first file and do some stuff..any help would be greatly appreciated. thanks JM
20 years ago
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.
20 years ago
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
20 years ago
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
20 years ago
Hello JavaGurus, I need to know if everyfile I read in has a 'Z' contained within the last line of the file. in particular it is the 10th byte from the EOF, but each file is different in length, so I'm using the .length() to get the total size but how would I say sBuffer.length() - 10 , then get the charAt() to check if it is a 'Z' thanks for anyone's help
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;

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);
sBuffer.charAt(??)
//System.out.println(sBuffer.length());
}
}//end main()
}//end class injRecFix
20 years ago
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 5th element of the last line of the same daily PUNCHfile. Problem is, sometimes 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- How would I write a small program to check the PUNCH.001 file to see if there is the 'X' and 'Z' line and if it is missing one, grab the second (punch.002) and put them together. I am kinda new to this stuff so any help is greatly appreciated. thnkas alot.
here is what I have so far:
byte[] btBuffer =null;
boolean bReadFile = false;
String sINFileName = null;
int i;
InputStream fin;

if(sINFileName == null)
sINFileName = "c:\\dailyfile\\receive\\Punch.001";

sINFileName = "c:\\dailyfile\\receive\\Punch.001";
fin = new FileInputStream(sINFileName);
btBuffer = new byte[fin.available()];
int i = 0;
while(i < btBuffer.length) {
i = fin.read();
btBuffer[i] = (byte)i;
i++;
}
fin.close();

20 years ago
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 5th element of the last line of the same daily PUNCHfile. Problem is, sometimes 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- How would I write a small program to check the PUNCH.001 file to see if there is the 'X' and 'Z' line and if it is missing one, grab the second (punch.002) and put them together. I am kinda new to this stuff so any help is greatly appreciated. thnkas alot.
here is what I have so far:


(edited by Cindy to format code)

[This message has been edited by Cindy Glass (edited May 09, 2001).]
20 years ago