mm2236
پنج شنبه 14 آذر 1387, 06:31 صبح
سلام دوستان
میشه کسی لطف کنه و بگه چطور میشه مرحله به مرحله از توی چند فولدر به سمت ریشه حرکت کرد مثلا به عنوان ورودی این رو بدیم ".."
مثال : c:\1\2\3
حالا بنویسیم ..
خروجی بشه این c:\1\2
کد من کلی خارج میشه ومیشه c:\
private void changeDirectory(DataInputStream in, DataOutputStream out) {
try {
File tmp = file;
String filePath = in.readUTF();
if (filePath.startsWith("..")) {
tmp = new File(file, filePath.substring(1));
} else {
tmp = new File(filePath);
}
if (tmp.isDirectory()) {
file = tmp;
out.writeShort(0);
} else {
out.writeShort(-1);
}
} catch (Exception e) {
try {
out.writeShort(-1);
} catch (Exception ie) {
}
}
}
ممنون و یا علی
میشه کسی لطف کنه و بگه چطور میشه مرحله به مرحله از توی چند فولدر به سمت ریشه حرکت کرد مثلا به عنوان ورودی این رو بدیم ".."
مثال : c:\1\2\3
حالا بنویسیم ..
خروجی بشه این c:\1\2
کد من کلی خارج میشه ومیشه c:\
private void changeDirectory(DataInputStream in, DataOutputStream out) {
try {
File tmp = file;
String filePath = in.readUTF();
if (filePath.startsWith("..")) {
tmp = new File(file, filePath.substring(1));
} else {
tmp = new File(filePath);
}
if (tmp.isDirectory()) {
file = tmp;
out.writeShort(0);
} else {
out.writeShort(-1);
}
} catch (Exception e) {
try {
out.writeShort(-1);
} catch (Exception ie) {
}
}
}
ممنون و یا علی