this codes works with 1.5 , but it does not work with 1.4..
The error sign is that the method format(String, Object[]) is undefined for the type String.
can you help me how it works with 1.5?
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
String [] test =null;
String str1="Today";
String str2="is";
String str3="monday";
String str4="good";
String format = "%1$-9s%2$-3s";
format +="%3$-30s%4$-30s\n";
test = new String[] {str1, str2, str3,str4};
File f = new File("D:\\temp\\test.txt");
try
{
if ( f.exists() )
{
PrintStream ps = new PrintStream(new FileOutputStream("D:\\temp\\test.txt"));
ps.println(String.format(format,(Object[])test));
ps.flush();
ps.close();
}
else
{
PrintStream ps = new PrintStream(new FileOutputStream("D:\\temp\\test.txt"));
ps.println(String.format(format,(Object[])test));
ps.flush();
ps.close();
}
}
catch (Exception e)
{
System.out.println(e);
}
}
}
The error sign is that the method format(String, Object[]) is undefined for the type String.
can you help me how it works with 1.5?
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
String [] test =null;
String str1="Today";
String str2="is";
String str3="monday";
String str4="good";
String format = "%1$-9s%2$-3s";
format +="%3$-30s%4$-30s\n";
test = new String[] {str1, str2, str3,str4};
File f = new File("D:\\temp\\test.txt");
try
{
if ( f.exists() )
{
PrintStream ps = new PrintStream(new FileOutputStream("D:\\temp\\test.txt"));
ps.println(String.format(format,(Object[])test));
ps.flush();
ps.close();
}
else
{
PrintStream ps = new PrintStream(new FileOutputStream("D:\\temp\\test.txt"));
ps.println(String.format(format,(Object[])test));
ps.flush();
ps.close();
}
}
catch (Exception e)
{
System.out.println(e);
}
}
}