I want to apply unzipping the file using zipme cn1 library (codenameone library). Is there any examples on how to do it? Can anyone give me the starting point? So far I have tried the following code but I am not sure where to keep dataName.zip file in the project and the folder to keep all the files after unzipping.
#Override
protected void beforeMain(Form f) {
net.sf.zipme.ZipEntry dataZE;
InputStream isData = getClass().getResourceAsStream("/" + "dataName" + ".zip");
StringBuffer sbData = new StringBuffer();
ZipInputStream dataZIS = new ZipInputStream(isData);
try {
while ((dataZE = dataZIS.getNextEntry()) != null) {
//how to extract the zip file in a separate folder...
dataZIS.closeEntry();
}
} catch (IOException ex) {
System.out.println("zip exception");
}
}
The above code gives following error:
cannot find symbol
InputStream isData = getClass().getResourceAsStream("");
symbol: method getResourceAsStream(String)
One more thing, why cant I use the following to get the zip file as in core java
ZipInputStream zis = new ZipInputStream(new FileInputStream("C:\\abc.zip"));
// it gives "FileInputStream: cannot find symbol"
How can I extract the zip file in a separate folder?
You should use Display.getInstance().getResourceAsStream().
FileInputStream isn't supported in Codename One which uses FileSystemStorage. The FileInputStream and File API's assume many things about the underlying OS that aren't always true.
Related
I'm trying to generate qrcode code in my application with qrgen and then saved in specific file but there is a problem in the libary 'java.io.FileOutputStream' where it can not be found. i want to know how to replace the libary and if there is another way to generate qrcode please share it with me
ByteArrayOutputStream out =QRCode.from(s).to(ImageType.PNG).stream();
try {
FileOutputStream fout = new FileOutputStream(new File(
"C:\\Users\\Public\\Pictures\\Sample Pictures\\QR_Code.JPG"));
fout.write(out.toByteArray());
fout.flush();
fout.close();
} catch (Exception e) {
// Do Logging
}
That isn't supported. Mobile devices don't have a file system in the way desktops have so this logic just won't work. There is a file system but it's to a large part private to the application, see: https://www.codenameone.com/manual/files-storage-networking.html
I want to upload an image with codename one the issue is when i upload it i get the wrong image name and path , let me explain more so this is the code :
imaged.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent evt) {
Display.getInstance().openImageGallery(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
if (ev != null && ev.getSource() != null) {
String filePath = (String) ev.getSource();
int fileNameIndex = filePath.lastIndexOf("/") +1;
String fileName = filePath.substring(fileNameIndex);
System.out.println("image : "+ fileName);
}
}
});
}
});
c3.add(imaged);
i want to get the image name to insert it into my data base the lint that i gott is :
C:/Users/Emel/AppData/Local/Temp/temp8005230168902905005..png
the image which i'm selecting is hosted on my wamp server under the www folder:
http://localhost/PiWeb1/TeamFlags/es.png
which is wrong even the file name is wrong how can i get the real path and file name!
This is a bit problematic on devices. They are very inconsistent when it comes file system/media so we try to replicate some of those problems in the simulator by copying the selection to the side.
The reason is simple, say you had access to the image directory of the phone you could read and upload all the images without the users consent. So they OS copies an image and gives you access only to that data.
You might have better luck with this on devices, if not you might have better luck with: https://www.codenameone.com/blog/native-file-open-dialogs.html
As a side note your URL won't be an http URL it will be a file URL.
I have met some strange trouble with reading file at Intellij Idea and on Windows 8.1.
And always I got FileNotFoundException.
Here is code snippet:
public XlsReader(String fileName, String sheetName) {
open(fileName, sheetName);
}
public void open(String fileName, String sheetName) {
InputStream fis = null;
try {
if (sheetName == null || sheetName.isEmpty()) {
throw new IllegalArgumentException("Please, provide sheet name");
}
Logger.logDebug("PATH: " + new File(".").getAbsolutePath());
fis = new FileInputStream(fileName);
String resourceFilePath = this.getClass().getResource(fileName).getFile();
Logger.logDebug(resourceFilePath);
fis = new FileInputStream(resourceFilePath);
XSSFWorkbook workBook = new XSSFWorkbook(fis);
sheet = workBook.getSheet(sheetName);
getMetaData();
I couldn't understand why at this line:
new FileInputStream(fileName)
I have got this exception.
And when chcenging path from:
xls = new XlsReader("InputDataIndirect.xlsx", "Calculator");
to:
xls = new XlsReader("test/InputDataIndirect.xlsx", "Calculator");
And it works now.
Here is project struckture:
I tried to load file from class path as well this.getClass().getResource(fileName).getFile() but it wasn't successful.
Any suggestions?
If you're running a main method or test from inside IntelliJ idea, it uses the root of the project as the root to load files from. Therefore, it will look under new_automation, so you need to add the test folder to your path.
To change this, you can change the working directory location in your run configuration to the location you want it to look in for files.
I'm using libvlc library. And it works well when I play the video file, that I have chosen in openFileDialog previously. But my goal is streaming video from webcam and previewing it.
I made libvlc show webcam video on the screen, but when i commented out the openFileDialog.Show() line (that I don't need anymore), "Entry point couldn't be found in the library" error dialogs started poping out for every libvlc plugin (that is basicaly a .dll file).
private void btPlay_Click(object sender, EventArgs e)
{
/*
if (openFileDialog1.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
* */
CleanUp();
string pluginPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "plugins");
string[] args = new string[]{
"--no-qt-error-dialogs",
"--ignore-config",
"--quiet",
"--plugin-path=" + pluginPath
};
//LibVlc initialization, that is where ERORR OCCURES
vlcInst = new VlcInstance(args);
/* Input media settings */
//VlcMedia media = new VlcMedia(vlcInst, openFileDialog1.FileName);
VlcMedia media = new VlcMedia(vlcInst, "dshow://");
LibVlc.libvlc_media_add_option(media.handle, "dshow-vdev=USB2.0 UVC VGA WebCam");
LibVlc.libvlc_media_add_option(media.handle, "dshow-adev=none");
/* Output media settings */
string[] outputOptions = new string[] {
"sout=#duplicate{",
"dst=",
"display",
",",
"dst=",
"'",
"transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100}",
":http{mux=ffmpeg{mux=flv},dst=:666/}",
"'",
"}"
};
LibVlc.libvlc_media_add_option(media.handle, String.Concat(outputOptions));
streamer = new VlcStreamer(media);
media.Dispose();
streamer.Drawable = mediaPanel.Handle;
streamer.Play();
}
private void CleanUp()
{
if (streamer != null)
{
streamer.Stop();
streamer.Dispose();
}
}
I can't see any relations between OpenFileDialog and libvlc plugins.
What can cause such a problem?
EDITED:
After I skip all error dialogs, program continues working.
When I was using VLC player, it made duplicates of the plugins in "plugin" folder. In my app I used those plugins and was getting errors. After I downloaded and unpacked new instance of the player, I discovered that there were no duplicates of the plugins, so I made a conclusion that the player makes copies of plugins when you launch it first time (didn't test it).
When I replaced my plugin folder with new one, all the errors were gone.
all. I have a problem with uploading of the file in Silverlight application. Here is a code sample. In case when this file is opened in other application (excel or word for example) it fails to open it, otherwise it's working fine. I'm using OpenFileDialog to choose the file and pass it to this function.
private byte[] GetFileContent(FileInfo file)
{
var result = new byte[] {};
try
{
using (var fs = file.OpenRead())
{
result = new byte[file.Length];
fs.Read(result, 0, (int)file.Length);
}
}
catch (Exception e)
{
// File is in use
}
return result;
}
Is there any way i can access this file or should i just notify the user that the file is locked?
You should notify the user that the file is currently in use by another program. If another program has the file open with a lock that does allow a shared read there is no way to bypass this lock.