This question may sound similar ,but non of the previous questions have been helpful to me.
In my app there are 2 activities,and 5 .java classes.
I need to know the value of an attribute which is there in the dependent classes (parking.java) (not in Main_Activity).
Till time i have tried putting
System.out.println ,Log.d/e/v/i ,but nothing seems to print my value.
what ever operations I tried,I did only in that particular class.(parking.java)
Also I have set debuggable =true in manifest file.
why the values are not getting printed ,am I putting them in wrong place ? ,or something else needs to be done
Please help
Here is the code
public void setLongitude(String Longitude){
try
{
ExifInterface exif = new ExifInterface(sd.toString());
_longitude=getExifTag(exif,ExifInterface.TAG_GPS_LONGITUDE);
Log.e("Tagname","_longitude");
}
catch(IOException e)
{
e.printStackTrace();
}
}
i have put Tagname as "Nihar"
still no success,
This is the change I have made ,
try
{
ExifInterface exif = new ExifInterface(sd.toString());
_longitude=getExifTag(exif,ExifInterface.TAG_GPS_LONGITUDE);
Log.v("Tagname",_longitude);
}
catch(IOException e)
{
e.printStackTrace();
}
Here is the image
Related
I'm using a Jave program to get NSE share price data from NSE's website like this for example:
url = new URL("https://archives.nseindia.com/archives/equities/bhavcopy/pr/PR071122.zip");
f = new File("NSEData.zip");
try {
FileUtils.copyURLToFile(url, f);
} catch (Exception e) {
}
The above code works for dates where market data exists, like 07/11/22 . However, where data does not exist, like on 08/11/22, the url is broken and the copyURLToFile line gets stuck indefinitely during runtime (replacing 071122 with 081122 in the url/code above will cause it to get stuck). Is there an easy way to get the program to recognize that the url for a certain date is broken (eg. https://archives.nseindia.com/archives/equities/bhavcopy/pr/PR081122.zip) and therefore ignore and continue past the try block without getting stuck?
My current workaround is to check whether a certain date is a market holiday using a DayOfWeek check as well as a HashSet containing a list of public holidays, but this is not perfect.
So, basically your URL is returning 500 error upon requesting for invalid date. You can simply use the another method available in FileUtils
https://commons.apache.org/proper/commons-io/javadocs/api-2.5/org/apache/commons/io/FileUtils.html#copyURLToFile(java.net.URL,%20java.io.File,%20int,%20int)
Example code : (Adjust timeouts as per your requirement)
var url = new URL("https://archives.nseindia.com/archives/equities/bhavcopy/pr/PR081122.zip");
var f = new File("NSEData.zip");
try {
FileUtils.copyURLToFile(url, f, 5000, 5000);
} catch (Exception e) {
}
I am using Eclipse to get data from the DB and populate a PDF. I created a form and named the fields. Everything was working fine before my computer crashed and I lost my code. I had to revert back to an older version of my code. I updated my code to populate some new fields that were added on the PDF before my computer crashed. Those new fields won't show the data.
I know the problem is not within getting the data from the DB because I can populate an older field with the new data.
My first thought is that I have to initialize the new fields but I don't know where I would do that. I did a search for a field that is showing but I only saw my code where I populate that field.
QDOB1 is an older field and is populated on the PDF.
dp.mdf("QDOB1", sChildren[1]);
QCHILD1 is a new field and won't populate.
dp.mdf("QCHILD1", sChildren[0]);
I can use sChildren[0] to populate the QDOB1 field.
dp.mdf("QDOB1", sChildren[0]);
Here is my code for dp.mdf which populates the field on the PDF.
public void mdf(String uk, String vl)
{
if ((vl != "") && (vl.trim().length() != 0))
{
AcroFields af = this.ps.getAcroFields();
try
{
af.setField(uk, vl);
}
catch (IOException e)
{
JOptionPane.showMessageDialog(null, e.toString());
System.exit(0);
}
catch (DocumentException e)
{
JOptionPane.showMessageDialog(null, e.toString());
System.exit(0);
}
}
}
Do the fields on the PDF need to be initialized? If so, where do I find the file that does this? I can't find an XML file attached to this project.
I realized the form field names are case sensitive. It now works.
I know that this a very common error, and I've read dozens of posts about such errors on SO already, but for some reason, absolutely nothing seems to be working out.
My ultimate object is to read an image from a particular location (in specific, the data folder) that is present at the same level as src in the project folder, and create a button with that image. However, I seem unable to read the image, and keep getting null.
Moreover, I have tried all possible combination I could think of:
gitinit.png
//gitinit.png
\gitinit.png
/gitinit.png
\gitinit.png
data/gitinit.png
data//gitinit.png
data\gitinit.png
data\gitinit.png
all out of sheer, meaningless frustration...
I'm using Eclipse. However, the project is being built with ant.
Here is the structure of my project:
As is visible, I've added gitinit.png everywhere possible, but to no avail.
As I read somewhere, I even tried adding data folder into the build path, but yet again, hopeless.
I realize that in this case, absolute path of the form "/data/gitinit.png" would be ideal, but here's another issue. What I'm working on is a tool for Processing. The tool is called from within Processing when it is running. When I run
System.out.println(this.getClass().getResource("/").getPath());
I get the following output:
/C:/Program%20Files/processing-2.1.1-windows64/processing-2.1.1/lib/
(with the / before C:). This folder has the following contents:
but when I run
System.out.println(this.getClass().getResource("").getPath());
I get the following output:
file:/C:/Users/MYPC/Documents/Processing/tools/GitManager/tool/GitManager.jar!/git_manager/tool/
The contents of this jar file are:
Here is the code I used. I've used 3 different ways of doing it (one of them came in the Processing Tool Template repo's readme), though they all essentially do the same thing. Again, the ultimate aim is to load an icon onto the button.
// some other function that executes during runtime
ImageIcon init = createImageIcon("gitinit.png", "git init Icon");
System.out.println("-------------------------------------");
loadImage("gitinit.png");
b.setIcon(new ImageIcon(("src\\gitinit.png")));
System.out.println(b.getIcon());
public Image loadImage(String theFilename) {
if (theFilename.startsWith(File.separator)) {
return new ImageIcon(theFilename).getImage();
} else {
URL img;
try{
img = this.getClass().getResource(getPath(theFilename));
return new ImageIcon(img).getImage();
}
catch (NullPointerException n)
{
//System.out.println("Null pointer Exception");
n.printStackTrace();
return null;
}
}
}
protected ImageIcon createImageIcon(String path, String description) {
java.net.URL imgURL;
try{
//imgURL = GitOptionToolbar.class.getResource(path);
imgURL = GitOptionToolbar.class.getClass().getResource(path);
}
catch(NullPointerException n)
{
imgURL = null;
System.out.println("null");
}
if (imgURL != null) {
System.out.println("Found " + path);
return new ImageIcon(imgURL, description);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
public String getPath(String theFilename) {
if (theFilename.startsWith("/")) {
return theFilename;
}
return File.separator + "data" + File.separator + theFilename;
}
So, well, what I think is to be done is to somehow move up the present path by 3 levels, then use the relative "data/gitinit.png", or "data/tools/xyz.png", but how do I do this?
Also, is this hypothesis correct??
I know this question is really long, and I'm sorry, I just wanted to put forth all of my experiments till now. Further, I know a lot of things are random, especially trying out different combinations of foldername, /, \ and filename, and also putting gitinit.png in every possible folder, and I apologize for that as well. Its just that I wanted to try out everything I could before posting here :)
Thanks!
You need to use
getResource("/data/toolbar/logos/gitnit.png")
The complete path from data all the way to the image. I'n not used to using Eclispe and not used to having the "data" dir on the same level at the src. In Netbeans I have it in the src, but it looks like the Eclipse takes care of that for you, looking at your image.
Hello at all the community ! I'm tring to change the frequency clock of the cpu but i'm a problem. To change the clock frequency i need to modify the file scaling_max_freq (/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq) but... this file has these permissions: rw-rw---- so with a file manager with root permissions i change rw-rw---- to rwxrwxrwx and all works fine (in this mode i can set the cpu frequency, with rw-rw---- permissions i can not do it). The code that i use for set the clock is this
public static boolean setClock(String filePath, String value) {
try {
fileWriter = new FileWriter(filePath);
fileWriter.write(value);
fileWriter.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
Now the question is: how can i set the permission for the file with code? how can i set rwxrwxrwx for the file scaling_max_freq? Thanks in advance.
You can't using Java 6.
You can using Java 7:
Files.setPosixAttributes(path, EnumSet.allOf(PosixFilePermission.class));
Now the question is why. You normally should not do it at all. Especially on a sysfs file.
You could try using Runtime but as fge stated you might not be able to set permission on your file system.
Note: Please do not judge this question. To those who think that I am doing this to "cheat"; you are mistaken, as I am no longer in school anyway. In addition, if I was, myself actually trying to cheat, I would simply use services that have already been created for this, instead of recreating the program. I took on this project because I thought it might be fun, nothing else. Before you down-vote, please consider the value of the question it's self, and not the speculative uses of it, as the purpose of SO is not to judge, but simply give the public information.
I am developing a program in java that is supposed intentionally corrupt a file (specifically a .doc, txt, or pdf, but others would be good as well)
I initially tried this:
public void corruptFile (String pathInName, String pathOutName) {
curroptMethod method = new curroptMethod();
ArrayList<Integer> corruptHash = corrupt(getBytes(pathInName));
writeBytes(corruptHash, pathOutName);
new MimetypesFileTypeMap().getContentType(new File(pathInName));
// "/home/ephraim/Desktop/testfile"
}
public ArrayList<Integer> getBytes(String filePath) {
ArrayList<Integer> fileBytes = new ArrayList<Integer>();
try {
FileInputStream myInputStream = new FileInputStream(new File(filePath));
do {
int currentByte = myInputStream.read();
if(currentByte == -1) {
System.out.println("broke loop");
break;
}
fileBytes.add(currentByte);
} while (true);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(fileBytes);
return fileBytes;
}
public void writeBytes(ArrayList<Integer> hash, String pathName) {
try {
OutputStream myOutputStream = new FileOutputStream(new File(pathName));
for (int currentHash : hash) {
myOutputStream.write(currentHash);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//System.out.println(hash);
}
public ArrayList<Integer> corrupt(ArrayList<Integer> hash) {
ArrayList<Integer> corruptHash = new ArrayList<Integer>();
ArrayList<Integer> keywordCodeArray = new ArrayList<Integer>();
Integer keywordIndex = 0;
String keyword = "corruptthisfile";
for (int i = 0; i < keyword.length(); i++) {
keywordCodeArray.add(keyword.codePointAt(i));
}
for (Integer currentByte : hash) {
//Integer currentByteProduct = (keywordCodeArray.get(keywordIndex) + currentByte) / 2;
Integer currentByteProduct = currentByte - keywordCodeArray.get(keywordIndex);
if (currentByteProduct < 0) currentByteProduct += 255;
corruptHash.add(currentByteProduct);
if (keywordIndex == (keyword.length() - 1)) {
keywordIndex = 0;
} else keywordIndex++;
}
//System.out.println(corruptHash);
return corruptHash;
}
but the problem is that the file is still openable. When you open the file, all of the words are changed (and they may not make any sense, and they may not even be letters, but it can still be opened)
so here is my actual question:
Is there a way to make a file so corrupt that the computer doesn't know how to open it at all (ie. when you open it, the computer will say something along the lines of "this file is not recognized, and cannot be opened")?
I think you want to look into the RandomAccessFile. Also, it is almost always the case that a program recognizes its file by its very start. So open the file and scramble the first 5 bytes.
The only way to fully corrupt an arbitrary file is to replace all of its contents with random garbage. Even then, there is an infinitely small probability that the random garbage will actually be something meaningful.
Depending on the file type, it may be possible to recover from limited - or even from not so limited - corruption. E.g.:
Streaming media codecs are designed with network packet loss take into account. Limited corruption may show up as picture artifacts, or even as a few lost frames, but the content is usually still viewable.
Block-based compression algorithms, such as bzip2, allow undamaged blocks to be recovered.
File-based compression systems such as rar and zip may be able to recover those files whose compressed data has not been damaged, regardless of damage to the rest of the archive.
Human-readable text, such as text files and source code files, is still viewable in a text editor, even if parts of it are corrupt - not to mention its size that does not change. Unless you corrupted the whole thing, any casual reader would be able to tell whether an assignment was done and whether the retransmitted file was the same as the one that got corrupted.
Apart from the ethical issue, have you considered that this would be a one-time thing only? Data corruption does happen, but it's not that frequent and it's never that convenient...
If you are that desperate for more time, you would be better off breaking your leg and getting yourself admitted to a hospital.
There are better ways:
Your professor accepts Word documents. Infect it with a macro virus before sending.
"Forget" to attach the file to the email.
Forge the send date on your email. If your prof is the kind that accepts Word docs, this may work.