Tina Guilder

Greenhorn
+ Follow
since Aug 23, 2006
Merit badge: grant badges
For More
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 Tina Guilder

the file is created..but nothing in it. I changed the -1 to zero and now it works.. thank you!

Tina
17 years ago
ive been working on this code, and i am stumped again... I have to make it so if a file is empty the progam will not work. The program still works even if the file is empty... here is my code.. any help would be great!!! thank you!!

Tina
import java.io.*;



public class program {
//usage


public static void usage()
{
System.err.println("ERROR: This progam requires exactly 2 arguments which are filenames:\n");
System.err.println("ERROR: first file contents are prepended to the second filename\n\n");
}
/**
* @param args
*/

public static void main(String[] args) {
// TODO Auto-generated method stub





if (args.length !=2)
{
usage();
return;
//terminate program,
}

File FirstFile = new File(args[0]);
//checking for first file
if (!FirstFile.exists())

{
System.err.println("ERROR: The first file does not exist!\n\n");
return;
//terminate program
//if file is empty program will fail
}
if (FirstFile.length() == -1){
System.err.println("ERROR: First Document is Empty");
return;


}
File SecondFile = new File(args[1]);
//check the second file
if (!SecondFile.exists())

{
System.err.println("ERROR: The Second file does not exist!\n\n");
return;
//terminate program
}
//if file is empty program will fail
if (SecondFile.length() == -1){
System.err.println("ERROR: Second Document is Empty");
return;

}
//Taking 2 files and creating a new file to combine the files as one
try {
//the file that will show up first in the document
File inputFile = new File("c:\\file1.txt");
File inputFile1 = new File("c:\\file2.txt");


File outputFile = new File("c:\\file3.txt");

FileInputStream fis1 = new FileInputStream(SecondFile);

FileInputStream fis2 = new FileInputStream(FirstFile);



FileOutputStream fos = new FileOutputStream(outputFile);
//writes second file to documents
int c = 0;
while ((c = fis1.read()) != -1){
fos.write(c);
}
fis1.close();
//writes first file under second file
while ((c = fis2.read()) != -1){
fos.write(c);
}
fis2.close();

fos.close();
//finds any error
} catch (FileNotFoundException e) {
System.err.println("FileStream: " + e);
} catch (IOException e) {
System.err.println("FileStreams: " + e);
}
}
}
17 years ago
Thank you everyone for your help..
17 years ago
fileinputstream???
17 years ago
is there a string that makes it so it will automatically put the contents into the file.. because the purpose of this is so you dont have to keep typing it.
17 years ago
this is what i have so far




EDIT by mw: Added Code Tags to original poster's indentation.
[ August 23, 2006: Message edited by: marc weber ]
17 years ago
I have made it so it creates file3.. I just cant get the information in the other files in there. do i have to do a sequencelist??? the 3rd file is successfully created, but no data
17 years ago
they are both text files, and a result of running the program is that the contents of the 2 file will be inserted about the first line of the 1st file...


Tina
17 years ago
I have 2 files, in which the 2nd file needs to be inserted above the first file... I am totally lost.. if you can help it would be wonderful!!! thank you


Tina
17 years ago