husonet yazdı:s.a.
Hocam import ettiğin paketleride yazarsan daha güzel olur...
Kolay Gelsin...
a.s. haklısınız ekledim.
Bu da javada yazdığım Tstringlist nesnesi. JAvada yeni olduğum için belki bana normal gelip de aslında komik kodlar olabilir
Bu örnekte
InputStream,OutputStream kullanımı, FileConnection ile dosya işlemlerinden sadece dosya açma syazma silme
doğrudan ddinamik dizi olmamamasına rağmen alternatif yollardan dinamik dizi çalışması bulunmaktadır
Sonuç itibariyle delphideki gibi olmasa da bir TStringlist nesnesi ortaya çıkıyor.
Kod: Tümünü seç
package src;
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import com.siemens.icm.io.file.FileConnection;
public class TStringList
{
private String[] fLines;
public TStringList()
{
fLines = new String[0];
}
public void Clear()
{
String[] fTemp = new String[0];
fLines = fTemp;
}
public void Add(String Value)
{
int oldsize = fLines.length;
String[] fTemp = new String[oldsize +1];
System.arraycopy(fLines, 0, fTemp, 0, fLines.length);
fLines = fTemp;
fLines[fLines.length-1]=Value;
}
public int Count()
{
return fLines.length;
}
public String Lines(int Index)
{
if ((Index>=0) & (Index<this.Count()))
{
return fLines[Index];
}
else
{
return "".toString();
}
}
public boolean LoadFromFile(String FileName)
{
try {
InputStream fOku;
FileConnection aFile = (FileConnection) Connector.open(FileName);
if (aFile.exists()) {
fOku = aFile.openInputStream();
byte ch[] = new byte[1024];
int okunanb = fOku.read(ch, 0, 1024);
int kelimeno = 1;
Clear();
String str = "";
for (int i = 0; i <= okunanb; i++)
{
if (ch[i] == '\r') {
kelimeno++;
Add(str);
str = "";
} else if (ch[i] == '\n')
{
} else {
str = str + (char) ch[i];
}
}
if (str.length() > 0)
Add(str);
fOku.close();
aFile.close();
return true;
} else
{
aFile.close();
return false;
}
} catch (Exception Exc) {
return false;
}
}
public boolean SaveToFile(String FileName)
{
try {
OutputStream fYaz;
FileConnection aFile = (FileConnection) Connector.open(FileName);
// Mevcut dosyayı sil
if (aFile.exists()) aFile.delete();
aFile.create();
fYaz = aFile.openOutputStream();
for (int i = 0; i<Count();i++)
{
fYaz.write(Lines(i).getBytes());
fYaz.write('\r');
fYaz.write('\n');
}
fYaz.close();
aFile.close();
return true;
}
catch (Exception E)
{
//System.out.println(E.getClass()+":"+E.getMessage());
return false;
}
}
}
Örnek kullanım
Kod: Tümünü seç
TStringList aList =new TStringList();
if (aList.LoadFromFile("file:///A:/Config.txt"))
{
//for (int i = 0; i<aList.Count();i++) System.out.println(aList.Lines(i));
if (aList.Count() >= 3) {
this.destHost = aList.Lines(0);
this.destPort = aList.Lines(1);
this.connProfile = aList.Lines(2);
}
...
...
...
yukarıdaki kullanımda
(aList.LoadFromFile("file:///A:/Config.txt")) şeklinde kullanım cihazdan cihaza farklılık gösterebilir.