Java Programs On Files
Java Programs On Files
import java.io.*;
class CopyDataFiletoFile
{
public static void main(String args[])throws IOException
{
FileInputStream Fread =new FileInputStream("Hello.txt");
FileOutputStream Fwrite=new FileOutputStream("Hello1.txt") ;
System.out.println("File is Copied");
int c;
while((c=Fread.read())!=-1)
Fwrite.write((char)c);
Fread.close();
Fwrite.close();
}
}
-----------
count no of characters and words in the given file:
// Java program to count the
// number of lines, words, sentences,
// characters, and whitespaces in a file
import java.io.*;
String line;
int wordCount = 0;
int characterCount = 0;
int paraCount = 0;
int whiteSpaceCount = 0;
int sentenceCount = 0;
try
{
FileWriter fw = new FileWriter(fileThree, true);
fw.write(content);
fw.close();
System.out.println("\nSuccessfully merged the content of two files
into the third file");
}
catch(IOException ioe)
{
System.out.println("\nSomething went wrong!");
System.out.println("Exception: " +ioe);
}
}
catch(IOException ioe)
{
System.out.println("\nSomething went wrong!");
System.out.print("Exception: " +ioe);
}
}
}
-------------------
//String Pallendrom or not
class Main {
public static void main(String[] args) {
if (str.toLowerCase().equals(reverseStr.toLowerCase())) {
System.out.println(str + " is a Palindrome String.");
}
else {
System.out.println(str + " is not a Palindrome String.");
}
}
}