V
vivienne wykes
I am writing a small class to read the file names from a folder and then
removes the extension.
ie Anderson.txt becomes Anderson.
I plan to then write the new file names to a db table.
I have an error here File dir = new File("C:\java_file_reader");
unexpected token...
Any ideas welcome ---Full code below.
Regards
import java.io.*;
public class AddWedding2
{
String i;
String filename;
public AddWedding2() { }
public static void main (String argv[])
{
File dir = new File("C:\java_file_reader");
String[] files = dir.list();
if (files == null)
{
// Either dir does not exist or is not a directory
}
else
{
for (int i=0; i<files.length; i++)
{
// Get filename of file or directory
String filename = files;
// Show the file names in stack trace
System.out.println("current text file is " + filename );
String no_extension;
//convert string array element into a char array
char [] charsfilename = filename.toCharArray();
int newlength = charsfilename.length -4;
no_extension = String.valueOf(charsfilename,0,newlength);
// Show the new file names in stack trace without extension
System.out.println("String no_extension " + no_extension );
}
}
}
}
removes the extension.
ie Anderson.txt becomes Anderson.
I plan to then write the new file names to a db table.
I have an error here File dir = new File("C:\java_file_reader");
unexpected token...
Any ideas welcome ---Full code below.
Regards
import java.io.*;
public class AddWedding2
{
String i;
String filename;
public AddWedding2() { }
public static void main (String argv[])
{
File dir = new File("C:\java_file_reader");
String[] files = dir.list();
if (files == null)
{
// Either dir does not exist or is not a directory
}
else
{
for (int i=0; i<files.length; i++)
{
// Get filename of file or directory
String filename = files;
// Show the file names in stack trace
System.out.println("current text file is " + filename );
String no_extension;
//convert string array element into a char array
char [] charsfilename = filename.toCharArray();
int newlength = charsfilename.length -4;
no_extension = String.valueOf(charsfilename,0,newlength);
// Show the new file names in stack trace without extension
System.out.println("String no_extension " + no_extension );
}
}
}
}