Error creating file using new File(directory).mkdir() [duplicate] - java

This question already has answers here:
Java - mkdir() not writing directory
(2 answers)
Closed 4 years ago.
I used new File(directory).mkdir() to create a new folder.
When i setdirectory = "C:\\Users\\livw\\Desktop\New folder\\5b27233480c016706f62a30a",
it works.
But when i add one more child folder to the directory: directory = "C:\\Users\\livw\\Desktop\\New folder\\5b27233480c016706f62a30a\\Samples",it doesn't create the folder.
How can i fix it?

Short and sweet,
Use mkdirs() instead of mkdir().
Hope it helps
Please in future refer to documentation.

directory = "C:\Users\livw\Desktop\New folder\5b27233480c016706f62a30a"
kindly check the directory address as file separator is not properly given before new Folder
import java.io.File;`
public class FileCreation {
public static void main(String[] args) {
new File("C:\\Users\\Master\\Desktop\\Horse\\demo\\devil").mkdir();
new File("C:\\Users\\Master\\Desktop\\Horse\\demo\\devil"+File.separator+"a").mkdir();
}
}

Related

Resources file is found by Gradle but not by Eclipse [duplicate]

This question already has answers here:
Different ways of loading a file as an InputStream
(6 answers)
Closed 7 years ago.
In my gradle java project, if I run ./gradlew run -PappArgs="['file.dat']" it is compiled and my app succesfully uses the file located in /src/main/resources/. I have integrated Eclipse with gradle and imported my project into Eclipse. When I run the app in Eclipse with filname specified in the Run Configurations argument list for the project, it fails to find the file.dat with this code:
import java.io.InputStream;
import java.util.Scanner;
public class MyClass {
public static void main(String[] args) {
final String fileName = args[0];
Scanner scanner = null;
try {
InputStream f = MyClass.class.getResourceAsStream(fileName);
scanner = new Scanner(f, "UTF-8"); // fails here saying f is null
} finally {
if (scanner != null) scanner.close();
}
}
}
Project tree is classic: myproj/src/main/java/MyClass.java, myproj/src/main/resources/file.dat and myproj/src/test/java/MyTest.java.
Both a set back and a blessing from Eclipse: all of your resources (files and pictures included) must be in the Build Path of your project. Ensure that this is indeed the case. If it is still the case, consider not using your method of finding the file to read from: a good old fashion
Scanner in=new Scanner(new File("src/main/resources/file.dat"));
will usually work.I hope this helps, and best of luck to you.

Keyboard cannot be resolved [duplicate]

This question already has answers here:
Java: Input strings with keyboard class
(5 answers)
Closed 9 years ago.
Im a newbie on Java. I get an error. These are my simple codes:
public class AreaRect {
public static void main(String[] args) {
int height, width, area;
System.out.print("yukseklik?");
height = Keyboard.readInt();
System.out.print("genislik?");
width = Keyboard.readInt();
area = height * width;
System.out.print(area);
}
}
and I get this error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Keyboard cannot be resolved
Keyboard cannot be resolved
at AreaRect.main(AreaRect.java:8)
I have a Keyboard.class file in the same directory with AreaRect.java..
Please can you tell me where am I wrong?
You need to organize your files into packages.
Move both Java files to a folder, e.g., mypackage. Then, add the following line to the top of each file:
package mypackage;
You can also have subpackages with nested folders. For example, the folder structure:
com
example
mypkg
AreaRect.java
Keyboard.java
could use the package com.example.mypkg.
If you are trying to compile your class via commandline with javac AreaRect.java, it will work to have the Keyboard.class file in the same folder.
If you are however trying to run this in Eclipse, it won't work until you add the .class file to a seperate folder and then add said folder to your buildpath via "Properties->Java Build Path->Add Class Folder".

unable to use .dll file in the Java code [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
how to use .dll files in java code?
The dll file, I am using, is giving error:
The error message is:
java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: Eagleye_parser
at java.lang.Runtime.load0(Runtime.java:767)
at java.lang.System.load(System.java:1005)
at test.TestDllJava.<clinit>(TestDllJava.java:15)
Exception in thread "main"
This is the code:
public class TestDllJava {
private static native String[] eagleye_fmu(String A);
public static void main(String[] args){
String[] ag = null;
String parameter = null;
parameter = "356188030442449 10250000 0001F464 0000EB34 0002CC7D 4xA0";
ag = eagleye_fmu(parameter);
System.out.println(ag);
}
static {
System.load("Eagleye_parser");
}
}
Please correct me, where I am doing wrong.
As the docs of load() specify:
Loads a code file with the specified filename from the local file
system as a dynamic library. The filename argument must be a complete
path name.
A better approach without stating an absolute path to library is by using loadLibrary() or maybe load(mapLibraryName(..)).
In Eclipse, you can specify native library folder in your project via project Properties -> Java build Path -> tab Libraries -> expand your System Library, click Native Library Location. Eclipse will build java.library.path for you and loadLibrary() will then see it easily.

R.raw.anything cannot be resolved [duplicate]

This question already has answers here:
R cannot be resolved - Android error
(108 answers)
Closed 10 years ago.
I'm developing an android apps with Eclipse.
In my app, I try to read a file : data.xml. I put it in res/raw/, and to access it i'm supposed to use getRessources().openRawResource(R.raw.data);
But Eclipse show me an error : "data" cannot be resolved or is not a field.
But the field is in the gen/R.java !!!
public final class R {
public static final class raw {
public static final int data=0x7f040000;
}
}
Any ideas ?
Thanks
Solution :
Import the right R.java files !
import my_package.R;
Stop trusting ctrl+shift+O ...
I already faced this problem several weeks ago. You simply have to use com.example.R (where com.example is the name of your package), because your IDE thinks that you are using android.R by default.
Try this out.
Try to clean and rebuild your project!
Or just delete import android.R;.
If that data.xml is in raw folder but still its not resolved once Clean and build your project and check.
Still error check this : Opening raw file

Netbeans / Java / Delete Files on Mac

I have a problem with my Java program. I want to delete a file on my hdd; I use a MacBook.
Here is my code:
public static void main(String[] args)
{
File actualFile = new File("/Users/luffy/test.xml");
actualFile.delete();
}
chmod is set! Help please.
Make sure that the file is not in use by another program.
Make sure that you have closed all streams accessing this file.

Categories