I have the bulk of the program written, but my problem is that I have some file that has 3 leading blank lines before the text begins. I need to remove those blank lines or skip the lines in the beginning of the file and just copy the remaining text to a new file. I can copy the file and create a new one, but it always has the leading whitespace and blank lines before the text. I tried skipBytes() but it is inefficient. Sample code would help.
Thanks in advance.
here's the code:
//Create a file chooser
final JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(convert3.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
try {
DataInputStream inStream= new DataInputStream(new FileInputStream(file));
(new FileInputStream(file));
DataOutputStream outStream = new DataOutputStream(new FileOutputStream( "c:/note1.txt",true));
//long size = file.length(); // Get size of file.
int c;
while ((c = inStream.read()) != -1)
{
outStream.write(c);
}
inStream.close();
outStream.close();
} catch ( java.io.IOException exception) {
if ( exception instanceof FileNotFoundException) {
System.out.println(
"file could not be found, \n" +
"or could not be opened.\n" +
"Please investigate and try again."
;
} // End if.
} // End try/ catch block.
} // End main.
}
// End class
public static void main(String[] args) {
JFrame frame = new convert3();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.pack();
frame.setVisible(true);
}
}
Thanks in advance.
here's the code:
//Create a file chooser
final JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(convert3.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
try {
DataInputStream inStream= new DataInputStream(new FileInputStream(file));
(new FileInputStream(file));
DataOutputStream outStream = new DataOutputStream(new FileOutputStream( "c:/note1.txt",true));
//long size = file.length(); // Get size of file.
int c;
while ((c = inStream.read()) != -1)
{
outStream.write(c);
}
inStream.close();
outStream.close();
} catch ( java.io.IOException exception) {
if ( exception instanceof FileNotFoundException) {
System.out.println(
"file could not be found, \n" +
"or could not be opened.\n" +
"Please investigate and try again."
} // End if.
} // End try/ catch block.
} // End main.
}
// End class
public static void main(String[] args) {
JFrame frame = new convert3();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.pack();
frame.setVisible(true);
}
}