I have a maven project, the character encoding is set as UTF-8 in my parent pom.
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
But in the Java file, some characters like ` or
has been used and it is causing compilation error to me.
In the Eclipse (Properties----Resource -----Text File encoding and Windows--preferences---workspace---text file encoding), I have specified the encoding as UTF-8. Please let me know how this issue can be solved.
PERL CODE TO DO CONVERSION STUFF
use strict;
use warnings;
use File::Find;
use open qw/:std :utf8/;
my $dir = "D:\\files";
find({ wanted => \&collectFiles}, "$dir");
sub collectFiles {
my $filename = $_;
if($filename =~ /.java$/){
#print $filename."\n";
startConversion($filename);
}
}
sub startConversion{
my $filename = $_;
print $filename."\n";
open(my $INFILE, '<:encoding(cp1252)', $filename) or die $!;
open(my $OUTFILE, '>:encoding(UTF-8)', $filename) or die $!;
}
These two lines do not start or perform re-encoding:
Opening a file with
>
truncates it, which deletes the content. See theopen
documentation for further details.Rather, you have to read the data from the first file (which automatically decodes it), and write it back to another file (which automatically encodes it). Because source and target file are identical here, and because of the quirks of file handling under Windows, we should write our output to a temp file:
If the files are small enough (hint: source code usually is), then you could also load them into memory: